我正试图与delegatecall建立一个简单的代理合同,但它一直失败,我不知道问题出在哪里。
Proxy.sol
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.6;
contract Proxy {
uint num;
address sender;
uint value;
function setVars(address _contract, uint _num) public payable returns(uint, string memory) {
(bool success, ) = _contract.delegatecall(
abi.encodeWithSignature("setVars(uint)", _num)
);
require(success, "Delegate call failed");
return (0, "");
}
}Logic.sol
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.6;
contract Logic {
uint num;
address sender;
uint value;
event ProxyEvent(uint, address, uint);
function setVars(uint _num) public payable {
num = _num;
sender = msg.sender;
value = msg.value;
emit ProxyEvent(num, sender, value);
}
}Test.js
describe("MyProxy", function() {
const value = ethers.utils.parseEther('0.01');
let proxy;
let logic;
before(async () => {
const Proxy = await ethers.getContractFactory("Proxy");
proxy = await Proxy.deploy();
await proxy.deployed();
const Logic = await ethers.getContractFactory("Logic");
logic = await Logic.deploy();
await logic.deployed();
})
it("should run delegatecall", async function() {
const tx = await proxy.setVars(logic.address, 15, { value, gasLimit: 100000 });
const receipt = await tx.wait();
console.log(receipt);
});
});Error
Error: VM Exception while processing transaction: revert Delegate call failed at Proxy.setVars (contracts/Proxy.sol:13)
提前感谢您的帮助!
发布于 2021-06-17 01:40:34
问题是函数签名,您必须使用uint256而不是uint。
abi.encodeWithSignature("setVars(uint256)", _num)https://ethereum.stackexchange.com/questions/102029
复制相似问题