我在使用“address.call(abi.encodeWithSignature(.)”时遇到了问题方法。下面是我正在Remix中测试的代码:
pragma solidity >=0.7.0 <0.9.0;
library lib {
event check(bool, bytes);
function remoteCall(address c) internal
{
(bool success, bytes memory data) = c.call(abi.encodeWithSignature("callback(bool)", true));
emit check(success, data);
}
}
contract main{
using lib for *;
event test(bool);
function useCallBack() external{
lib.remoteCall(address(this));
}
function callback(bool b) internal {
emit test(b);
}
}我总是得到:成功=错误,而“测试”事件永远不会触发。
有人知道我的代码出了什么问题吗?
发布于 2021-07-27 18:18:28
函数回调的可见性应改为公共或外部。由于它是内部的,所以地址类型c不能通过低级调用访问此函数。
library lib {
event check(bool, bytes);
function remoteCall(address c) internal
{
(bool success, bytes memory data) = c.call(abi.encodeWithSignature("callback(bool)", true));
emit check(success, data);
}}
contract main{
using lib for *;
event test(bool);
function useCallBack() external{
lib.remoteCall(address(this));
}
function callback(bool b) public{
emit test(b);
}}https://ethereum.stackexchange.com/questions/104167
复制相似问题