Contract-Development
當我用 delegatecall 呼叫 ownerof 時,地址重新呼叫錯誤
我想呼叫函式“ownerof”契約,但它返回我類似的東西:0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000bc641d0c1acc8f85bb53aceade03bbc58de693d1
功能是:
function updateRaceLeaderboard( uint256 raceID, uint256[] memory _leaderboard ) public onlyOwner returns (bytes memory addr) { RaceleaderBoard[raceID] = _leaderboard; address contractAddress = 0x80AFf21544b6670fCfD813134C83Bb340307c453; (bool success, bytes memory returndata) = contractAddress.call( abi.encodeWithSignature("ownerOf(uint256)", 0) ); return returndata; }
我這樣稱呼它:
dev = accounts.add(config["wallets"]["from_key"]) print("Working on " + network.show_active()) trx = race.updateRaceLeaderboard( 0, [0], {"from": dev}, )
ownerOf(uint256) 函式位於不同的合約中:
https://mumbai.polygonscan.com/address/0x80AFf21544b6670fCfD813134C83Bb340307c453#readContract
成功 bool 返回 True
你知道我怎樣才能收到正確的地址嗎?
您需要使用解碼返回數據
abi.decode(returndata, (address))
在您說它沒有成功的評論中,它不是返回地址而是錯誤消息
該錯誤可以解釋為
0x 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000084 08c379a0 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000029 4552433732313a206f776e657220717565...
這
08c379a0
是一個錯誤簽名Error(string)
解碼
4552433732313a206f776e657220717565
它給出的字元串messgaeERC721: owner que
我的猜測是對應於
function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); }
我的第二個猜測是您不應該使用委託呼叫,而是呼叫或靜態呼叫。
範例如何解析返回的數據
(bool success, bytes memory returndata) = contractAddress.call( abi.encodeWithSignature("ownerOf(uint256)", 0) ); if (success) { (address owner) = abi.decode(returndata, (address)); return owner; }