Remix

Remix - 錯誤:無法對缺少名稱的簽名對象進行編碼

  • May 23, 2022

我正在嘗試在Remix中傳遞這個 JSON 對像數組:

[{"nft": "0xd914...", "id": 0},{"nft": "0xd914...", "id": 1},{"nft": "0xd914...", "id": 2}]

但是我收到此錯誤:

Error: cannot encode object for signature with missing names (argument="values", coder={"name":"address","type":"address","localName":null,"dynamic":false}, value={"nft":"0xd914...","id":0}, code=INVALID_ARGUMENT, version=abi/5.5.0)

這是功能:

function addAirdrops(Airdrop[] memory _airdrops) external {
   uint _nextAirdropId = nextAirdropId;
   for(uint i = 0; i < _airdrops.length; i++) {
     airdrops[_nextAirdropId] = _airdrops[i];
     IERC721(_airdrops[i].nft).transferFrom(
       msg.sender, 
       address(this), 
       _airdrops[i].id
     );
     _nextAirdropId++;
   }
 }

我錯過了什麼,或者它是一個混音錯誤?

如果你有以下結構

struct Airdrop {
  bytes32 nft;
  uint256 id;
}

然後輸入應如下所示:

[[bytes32-of-nft, id], [...], [...]]

例子:

[["0x3272323133313234323134323134313234000000000000000000000000000000", 2], ["0x3272323133313234323134323134313234000000000000000000000000000000", 3]]

bytes32 是 64 個字元 + 額外0x= 66 個字元

引用自:https://ethereum.stackexchange.com/questions/128741