首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未能调用委托- Failed ()

未能调用委托- Failed ()
EN

Ethereum用户
提问于 2021-06-16 22:43:06
回答 1查看 969关注 0票数 0

我正试图与delegatecall建立一个简单的代理合同,但它一直失败,我不知道问题出在哪里。

Proxy.sol

代码语言:javascript
复制
//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

代码语言:javascript
复制
//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

代码语言:javascript
复制
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)

提前感谢您的帮助!

EN

回答 1

Ethereum用户

回答已采纳

发布于 2021-06-17 01:40:34

问题是函数签名,您必须使用uint256而不是uint

代码语言:javascript
复制
abi.encodeWithSignature("setVars(uint256)", _num)
票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/102029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档