Skip to content

Instantly share code, notes, and snippets.

@imewish
Last active May 20, 2023 06:21
Show Gist options
  • Save imewish/fc5ef366753db486d4bd22fdb9ea57f6 to your computer and use it in GitHub Desktop.
Save imewish/fc5ef366753db486d4bd22fdb9ea57f6 to your computer and use it in GitHub Desktop.
// json
const ethers = require('ethers');
const { FormatTypes } = require('ethers/lib/utils');
const iface = new ethers.utils.Interface([
'event MyEvent(address recipient, address asset, uint256 amount)',
]);
jsonAbi = iface.format(FormatTypes.json);
console.log(JSON.stringify(JSON.parse(jsonAbi), null, 2));
// human readable
const {ethers} = require('ethers');
const { Interface, FormatTypes } = require('ethers/lib/utils');
let abi = [...]
// create the Ethers.js Interface used for translation,
// and pass only the desired ABI content
const iface = new Interface(abi);
// perform the translation
const formattedAbi = iface.format(FormatTypes.full);
// const translatedAbi = JSON.stringify(JSON.parse(formattedAbi));
console.log(formattedAbi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment