Solidity

如何使用 web3.py 正確格式化作為具有嵌套結構的結構的參數?

  • September 25, 2022

我有以下 ABI:

{
   "inputs": [{
           "components": [{
                   "internalType": "enum LibNFTOrder.TradeDirection",
                   "name": "direction",
                   "type": "uint8"
               }, {
                   "internalType": "address",
                   "name": "maker",
                   "type": "address"
               }, {
                   "internalType": "address",
                   "name": "taker",
                   "type": "address"
               }, {
                   "internalType": "uint256",
                   "name": "expiry",
                   "type": "uint256"
               }, {
                   "internalType": "uint256",
                   "name": "nonce",
                   "type": "uint256"
               }, {
                   "internalType": "contract IERC20TokenV06",
                   "name": "erc20Token",
                   "type": "address"
               }, {
                   "internalType": "uint256",
                   "name": "erc20TokenAmount",
                   "type": "uint256"
               }, {
                   "components": [{
                           "internalType": "address",
                           "name": "recipient",
                           "type": "address"
                       }, {
                           "internalType": "uint256",
                           "name": "amount",
                           "type": "uint256"
                       }, {
                           "internalType": "bytes",
                           "name": "feeData",
                           "type": "bytes"
                       }
                   ],
                   "internalType": "struct LibNFTOrder.Fee[]",
                   "name": "fees",
                   "type": "tuple[]"
               }, {
                   "internalType": "contract IERC1155Token",
                   "name": "erc1155Token",
                   "type": "address"
               }, {
                   "internalType": "uint256",
                   "name": "erc1155TokenId",
                   "type": "uint256"
               }, {
                   "components": [{
                           "internalType": "contract IPropertyValidator",
                           "name": "propertyValidator",
                           "type": "address"
                       }, {
                           "internalType": "bytes",
                           "name": "propertyData",
                           "type": "bytes"
                       }
                   ],
                   "internalType": "struct LibNFTOrder.Property[]",
                   "name": "erc1155TokenProperties",
                   "type": "tuple[]"
               }, {
                   "internalType": "uint128",
                   "name": "erc1155TokenAmount",
                   "type": "uint128"
               }
           ],
           "internalType": "struct LibNFTOrder.ERC1155Order",
           "name": "order",
           "type": "tuple"
       }
   ],
   "name": "getERC1155OrderHash",
   "outputs": [{
           "internalType": "bytes32",
           "name": "orderHash",
           "type": "bytes32"
       }
   ],
   "stateMutability": "view",
   "type": "function"
}

我想打電話給那個契約,但我一直收到錯誤

web3.exceptions.ValidationError:無法使用名稱getERC1155OrderHash、類型的位置參數和類型的(<class 'dict'>,)關鍵字參數辨識預期的函式{}。找到 1 個具有名稱的函式getERC1155OrderHash

$$ ‘getERC1155OrderHash(tuple)’ $$ 由於沒有匹配的參數類型,函式呼叫失敗。

在 Web3.py 文件中,它說結構參數可以作為字典傳遞,但這對我不起作用,我找不到我的錯誤:

order = {'direction':0, 'maker': '0x6bea7d5f80ab338e11f1a98a69d81ec669f88a28','taker':'0x0000000000000000000000000000000000000000','expiry': 2524604400, 'nonce': '110201411100000000000000000000000000000051746150322622858142265866466119123410','erc20Token':'0xdc31ee1784292379fbb2964b3b9c4124d8f89c60', 'erc20TokenAmount': 5000000000000000000, 'fees': [['0x0000000000000000000000000000000000000000', 0, b'0']], 'erc1155Token':'0xfc37b8f25b57bff5c1b6df2d76485079bdc133cf', 'erc1155TokenId':1665619200,'erc1155TokenProperties':[['0x0000000000000000000000000000000000000000', b'0']], 'erc1155TokenAmount':5000000000000000000}

這是針對 Goerli 網路上的 0x 協議

該錯誤通常意味著您的getERC1155OrderHash函式的一個或多個參數類型不正確。請檢查以確保您的getERC1155OrderHash函式具有正確的參數類型。此外,請檢查以確保地址的開頭或結尾沒有雙引號或空格。

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