I have following contract; I can call set()
with following byte array on solidity browser. The smart contract accepts the input as bytes32
. I assume if geth
and solidity browser
sees a string starting with 0x
, it converts it to byte
format.
Following transaction call works without having any problem.
myContract.set("0x15CEF23823A9410D60CB6E6CC56046EC6035A9353100476EA28C94752AF104CD")
myContract.get()
Returns: "0x15CEF23823A9410D60CB6E6CC56046EC6035A9353100476EA28C94752AF104CD
My contract:
contract Contract {
bytes32 public hash;
function set(bytes32 hash_) returns (bool success)
{
hash = hash_;
}
function get() constant returns bytes32 {
return hash;
}
}
I want to do same operation on Populus.
When I try to call it as on test_greeter.py
:
def test_greeter(web3, accounts, chain):
myContract, _ = chain.provider.get_or_deploy_contract('Lottery')
set_txn_hash = myContract.transact().set("0x15CEF23823A9410D60CB6E6CC56046EC6035A9353100476EA28C94752AF104CD")
It gives following error, I assume python sees the input given to set()
as string instead of bytes. And the string version of the input exceeds the byte32
.
@classmethod
def _encode_abi(cls, abi, arguments, data=None):
argument_types = get_abi_input_types(abi)
if not check_if_arguments_can_be_encoded(abi, arguments, {}):
raise TypeError(
"One or more arguments could not be encoded to the necessary "
"ABI type. Expected types are: {0}".format(
> ', '.join(argument_types),
)
)
E TypeError: One or more arguments could not be encoded to the necessary ABI type. Expected types are: bytes32
[Q] While using Populus on pytest how could I transfer byte array as an input to the contract like in solidity browser?
Thank you for your valuable time and help.