2 Star 3 Fork 4

GKing/Solidity8_perfect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
S_39_DelegateCall.sol 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
GKing 提交于 2022-11-10 14:41 . 委托调用合约
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
/**
A calls B, sends 100 wei
B calls C, sends 50 wei
A --> B --> C
msg.sender = B
msg.value = 50
execute code on C's state variables 改变C合约的状态变量
use ETH in C
A calls B, sends 100 wei
B delegatecall C
A --> B --> C
msg.sender = A
msg.value = 100
execute code on B's state variables 改变B合约的状态变量
use ETH in B
*/
contract TestDelegateCall {
uint public num;
address public sender;
uint public value;
address public owner;
function setVars(uint _num) external payable {
num = 2*_num;
sender = msg.sender;
value = msg.value;
}
}
// 用于升级合约,代理合约状态变量要和被调用合约状态变量顺序要一致。
contract DelegateCall {
uint public num;
address public sender;
uint public value;
function setVars(address _test, uint _num) external payable{
// _test.delegatecall(abi.encodeWithSignature("setVars(uint256)", _num));
(bool success, bytes memory data) = _test.delegatecall(
abi.encodeWithSelector(TestDelegateCall.setVars.selector, _num)
);
require(success, "delegatecall failed");
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jacky2code/solidity8_perfect.git
[email protected]:jacky2code/solidity8_perfect.git
jacky2code
solidity8_perfect
Solidity8_perfect
master

搜索帮助