npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web3-abi-coder

v2.0.0

Published

The best ABI Coder tool

Downloads

42

Readme

Web3 ABI Coder

Utils that encodes and decodes transactions and logs for evm.

https://web3w.github.io/web3-abi-coder/

Motivation

To solve the problem of unreadable web3.js and Ethers decoder data.

Features

  • Readable result
  • Input data decode
  • Logs decode
  • ERC20Coder,ERC721Coder, ERC1155Coder
  • Block tx decode
  • Receipt decode

Installation

npm i web3-abi-coder

Example

decodeBlock

import {
    ERC1155ABI, ERC721ABI, ERC20Coder,
    getBlockByNumber, getTransactionByHash, getTransactionReceipt
} from 'web3-abi-coder';
import Seaport from "./abi/Seaport.json"

const blockNum = 10862111 //"0xa5be1f"
const coder = ERC20Coder.addABI(ERC721ABI).addABI(ERC1155ABI).addABI(Seaport.abi)
const {result: block} = await getBlockByNumber(blockNum)
console.log(coder.decodeBlock(block))
/*
[
  {
    name: 'approve',
    type: 'function',
    values: {
      spender: '0xf2450ae4A2FEdC654C48f5FC1FdF596D05007761',
      amount: '200000000000000000000'
    },
    hash: '0x7f6c78ecac73137076d10429905c5c45b47bde030035f614601a3a1983c2e822'
  },
  {
    name: 'fulfillAdvancedOrder',
    type: 'function',
    values: {
      advancedOrder: [Object],
      criteriaResolvers: [],
      fulfillerConduitKey: '0x0000000000000000000000000000000000000000000000000000000000000000',
      recipient: '0xcBE352f2559fe4209DDa6Ee2779cE254d2347d91'
    },
    hash: '0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6'
  },
  ...
]
* */

decodeTransaction

const txHash = "0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6"
const txData = await getTransactionByHash(txHash)
const decodeData = seaportCoder.decodeTransaction(txData.result)
/*{
  "name": "fulfillAdvancedOrder",
  "type": "function",
  "values": {
    "advancedOrder": {
      "parameters": {
        "offerer": "0x9226f7dF5E316df051F0490cE3b753c51695D0Bb",
        "zone": "0x00000000E88FE2628EbC5DA81d2b3CeaD633E89e",
        "offer": [
          {
            "itemType": 2,
            "token": "0x1878AaD5E60704f3DEc1F46bcFbf632055FCDD18",
            "identifierOrCriteria": "1",
            "startAmount": "1",
            "endAmount": "1"
          }
        ]..
      }..
    }
    ....
}
*/

decodeTransactionReceipt

const txHash = "0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6"
const coder = ERC20Coder.addABI(ERC721ABI).addABI(ERC1155ABI).addABI(Seaport.abi)
const {result: receipt} = await getTransactionReceipt(txHash)
console.log(coder.decodeTransactionReceipt(receipt))
/*[
  {
    name: 'Transfer',
    type: 'event',
    values: {
      from: '0x9226f7dF5E316df051F0490cE3b753c51695D0Bb',
      to: '0xcBE352f2559fe4209DDa6Ee2779cE254d2347d91',
      amount: '1'
    },
    hash: '0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6'
  },
  {
    name: 'OrderFulfilled',
    type: 'event',
    values: {
      orderHash: '0xf9fc6150b8befdda825b0e6bdd8723105e010b32c67b1c2f9fc5b053d55b3d70',
      offerer: '0x9226f7dF5E316df051F0490cE3b753c51695D0Bb',
      zone: '0x00000000E88FE2628EbC5DA81d2b3CeaD633E89e',
      recipient: '0xcBE352f2559fe4209DDa6Ee2779cE254d2347d91',
      offer: [Array],
      consideration: [Array]
    },
    hash: '0xbfe24528d5e90822924687d28d55dc492a65660d205c5619d8116780c69497f6'
  }
]
*/

decodeInput

import Web3ABICoder,{ ERC20Coder} from 'web3-abi-coder';
import Seaport from "./abi/Seaport.json"

const seaCoder = new Web3ABICoder(Seaport.abi)
const inputData = seaCoder.encodeInput("getCounter", ["0x0A56b3317eD60dC4E1027A63ffbE9df6fb102401"])
const func = seaCoder.getFunctionName(inputData.substring(0, 10))
const decodeData = seaCoder.decodeInput(inputData)
/*
{
  name: 'getCounter',
  type: 'function',
  values: { offerer: '0x0A56b3317eD60dC4E1027A63ffbE9df6fb102401' }
}

*/

decodeLog


const erc20Log = {
    data: "0x0000000000000000000000000000000000000000000000370c9b5ef669c35300",
    topics: [
        '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
        '0x000000000000000000000000b5cfcb4d4745cbbd252945856e1b6eaadcf2fc4e',
        '0x000000000000000000000000694c6aea9444876d4fa9375fc9089c370f8e9eda',
    ]
}
const erc20LogData = ERC20Coder.decodeLog(erc20Log)
console.log(erc20LogData)
/*
{
  name: 'Transfer',
  type: 'event',
  values: {
    from: '0xb5CFcb4D4745cBBD252945856E1B6eaadCf2fC4E',
    to: '0x694c6aea9444876d4fA9375fC9089C370F8E9edA',
    value: '1015479348216300000000'
  }
}
*/ 

encodeInput


const transferCallData = ERC20Coder.encodeInput("transfer", ["0xad47d554e3a527d5cb4712b79eabba4f6152abcd", "2"])
const transferValue = ERC20Coder.decodeInput(transferCallData)
console.log(transferValue)
/*
{ 
    name: 'transfer',
    type: 'function',
    values: { to: '0xAD47D554E3A527D5Cb4712B79EaBBA4f6152abCd', amount: '2' }
}
*/

API

  • Web3ABICoder(abi) extends Interface
    • abi
      • ERC20ABI,ERC721,ERC1155
      • addABI(abi: ReadonlyArray<Fragment | JsonFragment>): Web3ABICoder
      • ...abiCoder
    • utils
      • getFunctionName(sighash: string):string
      • getFunctionSelector(name: string): { name: string, signature: string, sighash: string }[]
      • getFunctionSelectors(): { name: string, signature: string, sighash: string }[]
      • getFunctionSignature(name: string, type?: "minimal" | "json" | "full"): string[]
      • getEvent(nameOrSignatureOrTopic: string): EventFragment
      • getEvents(): { name: string, signature: string, topic: string }
      • ...Interface
    • decoding
      • decodeBlock(block): DecodeResult[]
      • decodeTransaction(transaction): DecodeResult[]
      • decodeTransactionReceipt(receipt): DecodeResult[]
      • decodeConstructor(data: string): DecodeResult
      • decodeInput(inputData: string): DecodeResult
      • decodeInputParams(funcName, inputCode)
      • decodeLog(log: { topics: string[], data: string }): DecodeResult
      • decodeOutput(nameOrSighash: string, outputData: string): DecodeResult
      • ...Interface
    • encoding
      • encodeInput(nameOrSighash: string, inputs: any[])
      • ...Interface
    • utils
      • get4Bytes
      • getTransferEvents