Solidity — Enable ABIEncoderV2 to use Structs as Function parameters

Dillon Vincent
Feb 3, 2019 · 1 min read

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store