Solidity — Enable ABIEncoderV2 to use Structs as Function parameters

If you’ve been developing on Ethereum you know the pain of not being able to pass structs from contract to contract or from web3 to contract. At Atra Blockchain Services we automate the creation and deployment of Ethereum contracts for our users and this limitation had a direct effect on our data storage service dTables.


Now, with the ABIEncoderV2 enabled you can pass a struct type into a function from web3 or another contract. When compiling a contract with ABIEncoderV2 enabled there are a few changes to the compiled ABI output. The ABI JSON will now include a new type called ‘tuple’ when it comes across structs as parameters in a function. The tuple type is paired with the property ‘components’, the components prop is an array with a list of {name, type} objects.

Below is an example of the ABI of a contract that uses a struct as an input parameter. Notice the type and components properties.

Below is an example storage contract that uses the new encoder

The use of structs in your function parameters can significantly reduce the clutter and complexity of your contracts while enabling them to be much more pleasant to interact with.

Make sure to check out our services and stay in touch.