请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

caller.sol 中点击 setCalleeX方法报错

老师请帮忙看看
错误信息:
transact to caller.setCalleeX errored: VM error: revert.
revert
The transaction has been reverted to the initial state.
Reason provided by the contract: “call failed”.
Debug the transaction to get more information.

callee.sol 代码:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;



// 被调用的契约
contract Callee{
    uint public x;
    function setX(uint _x)public returns(uint){
       x = _x;
       return  x;
    }
}

caller.sol 代码:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;
// 执行调用的契约
contract caller{

    address calleeAddress;
    uint public xx;
    constructor(address _calleeAddress){
      calleeAddress = _calleeAddress;
    }

    function setCalleeX(uint _x)public{
       bytes memory cd = abi.encodeWithSignature("setX(uint)", _x);
       (bool suc, bytes memory rst) = calleeAddress.call(cd);
       if(!suc){
         revert("call failed");
       }
       (uint x) = abi.decode(rst, (uint));
       xx = x;
    }
}

正在回答 回答被采纳积分+3

1回答

残照花开(Adams) 2023-08-24 09:09:14
cd = abi.encodeWithSignature("setX(uint)", _x   这里面的那个uint是uint256的别名,不能这样用,必须全名uint256. 课程里讲到了
0 回复 有任何疑惑可以回复我~
  • 提问者 lph0 #1
    那时候写的时候漏掉了 谢谢老师!
    回复 有任何疑惑可以回复我~ 2023-08-24 11:15:57
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号