I am trying to encode a struct as bytes with brownie and then pass the bytes as an argument to a smart contract.

contract C {
  struct S {
    uint256 a;
    uint256 b;

  function f(bytes memory d) external returns (uint256, uint256) {
  S memory s = abi.decode(d, (S));
  return (s.a, s.b);

With the contract above, how can I construct d with brownie such that it can be decoded into a struct in solidity? I see that brownie has ContractTx.encode_input(), but this requires a function signature. Thanks!

1 Answer 1


This can be solved with eth-abi package. Documentation can be found in https://eth-abi.readthedocs.io/en/latest/index.html.

For the example in the question, it can be called like:

import eth_abi
contract.f(eth_abi.encode_abi(['uint256', 'uint256'], [1, 2])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.