4
用户给A合约转账继续转账给B合约问题
source link: https://learnblockchain.cn/question/2554
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
用户给A合约转账继续转账给B合约问题 | 登链社区 | 技术问答
用户给A合约转账继续转账给B合约问题
大概逻辑是:用户调用函数转账给A合约,函数内继续把余额转账给B合约。
A合约代码:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract test2{
uint public value;
address public seller;
address public test1Adder;
constructor(address _add) public {
test1Adder = _add;
}
function tr() public payable {
seller = msg.sender;
value = msg.value;
payable(test1Adder).transfer(value);
}
// 查看合约内金额
function getBalance() public view returns(uint) {
return payable(address(this)).balance;
}
}
B合约代码:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract test1{
// 查看合约内金额
function getBalance() public view returns(uint) {
return payable(address(this)).balance;
}
}
执行tr方法结果:
如果把B合约的地址换成用户地址是可以转成功的,求大哥调教-.-
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK