I have a solidity function declared as:
function setUnitData(bytes32[10] my_input_array) public payable {...}
When I run this code:
contract = self.contract_instance['../contracts/test.sol:test']
test_byte = b'0x01234567890123456789012345678901' * 24
tx_hash = contract.functions.setUnitData(test_byte).transact({'from': self.w3.toChecksumAddress(unit['update_account']), 'gas': 3400000})
I get this ValidationError
:
web3.exceptions.ValidationError:
Could not identify the intended function with namesetUnitData
, positional argument(s) of type(<class 'bytes'>,)
and keyword argument(s) of type{}
.
Found 1 function(s) with the namesetUnitData
: ['setUnitData(bytes32[10])']
Function invocation failed due to no matching argument types.
Any possible or best way to send the python byte array or any workable type to this function?
Best Answer
The function
setUnitData(bytes32[10])
requires an array of 10 elements, each of which is 32 bytes of data. Since we don't know the purpose of the function, let's generate a some random data of that type:If looking at native bytes values in python makes you grumpy, you can convert to hex strings. Web3.py will accept either.
Now you can send a transaction with:
(
hex_array
also works, in place ofinput_array
)