其他分享
首页 > 其他分享> > solidity基础-call

solidity基础-call

作者:互联网

例子

receive

contract ReceiveTest {

  event Received(address caller, uint256 amount, string msg);

  function getBalance() public view returns(uint256){
        return address(this).balance;
  }
    
   function foo(string memory _msg, uint256 _x) public payable returns(uint256){
       emit Received(msg.sender, msg.value, _msg);
       return _x + 1;
   } 
}

call

contract Caller {

  event Re(bool succcess, bytes data);

  function callFoo(address payable _addr) public payable{
    (bool success, bytes memory data) = _addr.call{value: msg.value, gas: 10000}( 
        abi.encodeWithSignature("foo(string, uint256)", "call foo", 40000)
    );

    emit Re(success, data);

  }

}

 

标签:uint256,solidity,基础,value,call,msg,foo,public
来源: https://www.cnblogs.com/apenote/p/16355138.html