代码拉取完成,页面将自动刷新
pragma solidity ^0.4.25;//声明编译器版本,^表示向上兼容
/*
1、call()、delegatecall()成员函数 :
在一个合约内调用另外一个合约的函数还有可以附加value、gas
PS:elegatecall不可以附加value、gas
格式:被调用合约地址.call(被调用函数名前四个字节,被调用函数参数)
2、在CallTest合约中调用合约Called中的函数
*/
contract Called {
uint public n;
address public sender;
event logdata(bytes data);
constructor () public payable{
//构造函数可以转移以太币
}
function () public payable {
//回退函数
emit logdata(msg.data);
}
function setN(uint _n) public payable{
n = _n;
sender = msg.sender;//保存合约地址
}
function getBalance() public view returns (uint) {
return this.balance;
}
}
contract CallTest {
uint public n;
address public sender;
constructor () public payable{
}
function callandSetN(address _e, uint _n) public{
bytes4 methodId = bytes4(keccak256("setN(uint256)"));
require(_e.call.value(1 ether)(methodId, _n));
// _e.call.gas(1000)(methodId, _n);
// _e.call.gas(1000).value(1 ether)(methodId, _n);
}
// delegatecall只是调用代码,合约环境还是当前合约。
function delegatecallAndSetN(address _e, uint _n) public{
bytes4 methodId = bytes4(keccak256("setN(uint256)"));
_e.delegatecall(methodId, _n);
}
function callNoFunc(address addr) public returns (bool){
return addr.call("tinyxiong", 1234);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。