Properly format an argument that is a struct with nested structs, with web3.py

contract-invocationsoliditystructweb3.py

I have the following 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"
}

And I want to make a call to that contract but I keep getting the error

web3.exceptions.ValidationError:
Could not identify the intended function with name getERC1155OrderHash, positional argument(s) of type (<class 'dict'>,) and keyword argument(s) of type {}.
Found 1 function(s) with the name getERC1155OrderHash: ['getERC1155OrderHash(tuple)']
Function invocation failed due to no matching argument types.

In the Web3.py docs it says that structs arguments can be passed as a dictionary and but that didn't work for me, and I can't find my mistake:

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}

This is for the 0x protocol on the Goerli network

Best Answer

The error usually means that one or more arguments of your getERC1155OrderHash function are of incorrect type. Please check to make sure your getERC1155OrderHash function has the correct argument types. In addition, check to make sure there are no double quotes nor spaces at the beginning or end of your addresses.

Related Topic