原版的
在另一个带有参数的合约中调用一个函数并发送资金的一般语法是: 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)