Web3.py: Cannot send int256[] (list of integers) into function with parameter type int256[]

Created on 11 Mar 2021  路  4Comments  路  Source: ethereum/web3.py

  • Version: 5.17.0
  • Python: 3.8.8
  • OS: win (WSL 2, Ubuntu)
  • pip freeze output
anyio==2.2.0
attrs==20.3.0
base58==2.1.0
bitarray==1.2.2
blake2b-py==0.1.3
cached-property==1.5.2
certifi==2020.12.5
chardet==4.0.0
cytoolz==0.11.0
eth-abi==2.1.1
eth-account==0.5.4
eth-bloom==1.0.3
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.2.1
eth-tester==0.5.0b3
eth-typing==2.2.2
eth-utils==1.9.5
hexbytes==0.2.1
idna==2.10
iniconfig==1.1.1
ipfshttpclient==0.7.0a1
jsonschema==3.2.0
lru-dict==1.1.7
multiaddr==0.0.9
mypy-extensions==0.4.3
netaddr==0.8.0
packaging==20.9
parsimonious==0.8.1
pluggy==0.13.1
protobuf==3.15.5
py==1.10.0
py-ecc==4.1.0
py-evm==0.3.0a20
py-geth==2.4.0
pycryptodome==3.10.1
pyethash==0.1.27
pyparsing==2.4.7
pyrsistent==0.17.3
pysha3==1.0.2
pytest==6.2.2
requests==2.25.1
rlp==2.0.1
semantic-version==2.8.5
six==1.15.0
sniffio==1.2.0
sortedcontainers==2.3.0
toml==0.10.2
toolz==0.11.1
trie==2.0.0a5
typing-extensions==3.7.4.3
urllib3==1.26.3
varint==1.0.2
web3==5.17.0
websockets==8.1

What was wrong?

The code which produced the error:

The solidity function defined:

function initiateProviderCurve(bytes32 endpoint, int256[] memory curve, address broker) public {...}

does not accept the python list of integers I provide

accounts = w3.eth.accounts
term = [3, 0, 0, 3, 100000]
term = [Web3.toHex(t) for t in term]

contract.functions.initiateProviderCurve(
    Web3.toBytes(text="Valid endpoint"),
    term,
    accounts[0]).transact(
    {"from": accounts[0], "gas": 4e5, "gasPrice": 5e4})

Full output of the error:

web3.exceptions.ValidationError:
Could not identify the intended function with name `initiateProviderCurve`, positional argument(s) of type `(<class 'bytes'>, <class 'list'>, <class 'str'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `initiateProviderCurve`: ['initiateProviderCurve(bytes32,int256[],address)']
Function invocation failed due to no matching argument types.
  • What type of node you were connecting to:

hardhat test node.

How can it be fixed?

I think there is something I'm missing here, but I'm almost positive it has to do with the list/array input. str for address works on other functions, as do bytes for bytes32.

Most helpful comment

I think that's your gas and gasPrice. Try making those ints too

All 4 comments

@acemasterjb I think it's your toHex conversion because it returns a string. Do you still get the error if you try with the initial term?

@kclowes
When I do so, I get this

contract.functions.initiateProviderCurve(Web3.toBytes(text="valid endpoint"),
...
eth_utils/conversions.py", line 48, in to_hex
    raise TypeError(
TypeError: Unsupported type: '<class 'float'>'.  Must be one of: bool, str, bytes, bytearrayor int.

This is the start and end of the traceback, would you need the full traceback to get a better idea of what's going on?

I think that's your gas and gasPrice. Try making those ints too

@kclowes
makes perfect sense, thank you! I sometimes over look the fact that even 1e1 would be a float type.

Was this page helpful?
0 / 5 - 0 ratings