0.1.1 • Published 10 months ago

erc-abis-ts v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

erc-abis-ts

A collection of common ERC ABIs in human-readable form. ERCs are defined based on their required/optional items in the Ethereum Improvement Proposals list.

Installation

npm install erc-abis-ts

Usage

Viem

import { erc20Abi } from 'erc-abis-ts'
import { parseAbi, encodeFunctionData } from 'viem';

// Format the ABI from human-readable to JSON
const abi = parseAbi(erc20AbiHumanReadable);

// Encode calldata
const calldata = encodeFunctionData({
    abi: abi,
    function: 'balanceOf',
    args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC']
})

// Make a call to a contract
const balance = publicClient.readContract({
    address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
    abi: abi,
    method: 'balanceOf',
    args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC']
    })

Ethers

import { erc20Abi } from 'erc-abis-ts'
import { Interface, Contract } from 'ethers/lib/utils';

const iface = new Interface(erc20Abi);

// Format the ABI from human-readable to JSON
const abi = iface.format(FormatTypes.JSON)

// Encode calldata
const calldata = iface.encodeFunctionData('balanceOf', ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'])

// Make a call to a contract
const contract = new Contract('0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', erc20Abi, provider)
const balance = await contract.balanceOf('0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC')

// Note that with ethers you can use the human-readable ABI directly without conversion to JSON
0.1.1

10 months ago

0.1.0

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago