1.0.0 • Published 2 years ago

eth-abi-sort v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

eth-abi-sort

Sort an Ethereum ABI definition for easier comparison

Installation

npm install --global eth-abi-sort

Usage

Sort ABI files in place:

abi-sort abi.json

Or pipe an ABI into the command and redirect the output to a new file:

abi-sort < abi.json > sorted.json

It can also be used programatically:

const sortAbi = require("eth-sort-abi");
const abi = [
  // the ABI of a contract
];
const sortedAbi = sortAbi(abi);

How it works

The tool will place the events first, then the functions. Each group is sorted by signature, ascending. The signature is computed as "name(type,...)".

Motivation

When EVM contracts are compiled, the ABIs can be obtained. But the order of the descriptors inside the ABI and the order of the properties cannot be guaranteed. Depending on the contract code, compiler and versions used, the ABIs can be created with a different order.

To make comparisons easier, this tool can be used to deterministically sort ABIs.

License

MIT