如何在智能合约中调用另一个智能合约payable方法并发送资金和传参数

原版的

在另一个带有参数的合约中调用一个函数并发送资金的一般语法是: address.func.value(amount)(arg1, arg2, arg3)

func需要具有payable修改器(对于Solidity 0.4+)。

pragma solidity ^0.4.0;

contract PayMain {
  Main main;
  function PayMain(address _m) {
     main = Main(_m);
  }
  function () payable {
    // Call the handlePayment function in the main contract
    // and forward all funds (msg.value) sent to this contract
    // and passing in the following data: msg.sender
    main.handlePayment.value(msg.value)(msg.sender);
  }
}

contract Main {
  function handlePayment(address senderAddress) payable public {
      // senderAddress in this example could be removed since msg.sender can be used directly
  }
}

 

在Solidity 0.5+中,语法已更改为: address.call.value(msg.value)(arg1, arg2, arg3)

在Solidity 0.6+中,语法已更改为: address.function{value:msg.value}(arg1, arg2, arg3)

 

你可能感兴趣的:(智能合约,调用智能合约payable方法,智能合约调用智能合约发送资金)