Today we released v3.0 of ethers.js, a leading library for Ethereum dApps and web3.js alternative. To celebrate the release, this is the first post in a series on using some of the more interesting techniques and features available to Ethereum application.
The ABI (Application Binary Interface) is how a dApp communicates with a Solidity contract; by making function calls, returning data and receiving events. The classic ABI coder does not permit arrays of dynamic types, structs or nested variables between the Solidity contract and the dApp.
This article focuses on a new experimental feature of Solidity, the ABI v2 coder; which allows structs, nested and dynamic variables to be passed into functions, returned from functions and emitted by events.
This example is just a quick demo and should not be considered a production ready (or even production relevant), but is just to get a feel for the potential uses of the ABI v2 coder.
Once we have deployed this contract to the Ropsten Test Network we can begin to interact with it, first by adding a user using structured data.
Once the above transaction is mined, we can use the contract user getter to retrieve the structured data from the contract.
And if we install the onuseradded event listener on the contract, we will get notified whenever any user is added with the structured data.
Please keep in mind this is still considered a highly experimental feature.
In addition to structures and nesting, the ABI v2 coder enables arrays of dynamic objects such as string[] and uint256[][] which were previously not possible.
The ethers.js library aims to provide a single complete and secure library to handle all the functionality you need to safely and easily create Ethereum applications. Some of the extra features include:
- Connect to the Ethereum blockchain over JSON-RPC, INFURA, Etherscan, Web3 Providers or MetaMask (more back-end services coming soon)
- Tiny (79kb compressed; 242kb uncompressed)
- ENS names are first-class citizens; you can use them intead of an address in almost any function that takes an Ethereum address
- Large suite of test cases (~20,000), both hand-picked and procedurally generated
- Extensive documentation
- Fully MIT licensed (including all dependencies)
Thanks for reading, and I hope you found this useful. Please feel free to open any issues for ethers.js on GitHub or follow me on Twitter.