Skip to content

0xcompose/decode-anything-cli

Repository files navigation

decode-anything-cli

A CLI wrapper for @openchainxyz/abi-guesser to decode any ABI-encoded data without knowing the ABI.

Features

  • 🔍 Guess ABI types from encoded data automatically
  • 🎯 Decode function calldata including function selectors
  • 📊 Multiple output formats (human-readable or JSON)
  • 🚀 No ABI required - works with any properly encoded data

Installation

Global Installation

npm install -g decode-anything-cli
# or
yarn global add decode-anything-cli

Local Development

git clone <repository-url>
cd decode-anything-cli
yarn install
yarn build

Usage

Basic Usage

Decode ABI-encoded data:

decode-anything 0x0000000000000000000000000000000000000000000000000000000000000001

Decode Function Calldata

Include the 4-byte function selector (first 4 bytes of transaction calldata):

decode-anything --calldata 0xa9059cbb000000000000000000000000...

JSON Output

Get machine-readable JSON output:

decode-anything --json 0x0000000000000000000000000000000000000000000000000000000000000001

Command Line Options

USAGE:
  decode-anything <data> [options]

ARGUMENTS:
  <data>              Hex-encoded data (with or without 0x prefix)

OPTIONS:
  -j, --json          Output in JSON format
  -c, --calldata      Decode as function calldata (expects first 4 bytes to be function selector)
  -h, --help          Show this help message

Examples

Example 1: Simple uint256

$ decode-anything 0x0000000000000000000000000000000000000000000000000000000000000001

Guessed Parameter Types:
  [0] uint256

Decoded Values:
  [0] 1

Example 2: Address and Amount

$ decode-anything 0x000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000000000000000000000000000000000000000186a0

Guessed Parameter Types:
  [0] address
  [1] uint256

Decoded Values:
  [0] 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
  [1] 100000

Example 3: Function Calldata

$ decode-anything --calldata 0xa9059cbb000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000000000000000000000000000000000000000186a0

Function Fragment:
  guessed_a9059cbb(address,uint256)

Selector: 0xa9059cbb

Parameter Types:
  [0] address
  [1] uint256

Decoded Values:
  [0] 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
  [1] 100000

Example 4: JSON Output

$ decode-anything --json 0x0000000000000000000000000000000000000000000000000000000000000001

{
  "success": true,
  "types": [
    {
      "type": "uint256",
      "baseType": "uint256",
      "format": "uint256"
    }
  ]
}
{
  "decodedValues": [
    "1"
  ]
}

How It Works

This tool uses the abi-guesser library which:

  1. Analyzes the structure of ABI-encoded data
  2. Identifies parameter boundaries using 32-byte padding
  3. Detects dynamic types using offset pointers
  4. Infers specific types based on data patterns (addresses, uint sizes, etc.)

Note: This only works with abi.encode() formatted data. Data encoded with abi.encodePacked() cannot be reliably decoded without knowing the types beforehand.

Development

Build

yarn build

Run in Development

yarn dev <data> [options]

Type Checking

yarn check-types

Linting & Formatting

yarn lint
yarn format

Limitations

  • Only works with properly ABI-encoded data (using abi.encode())
  • Cannot decode abi.encodePacked() data (no type boundaries)
  • Type inference may not always be 100% accurate
  • Complex nested structures might have ambiguous types

Credits

Built on top of @openchainxyz/abi-guesser by the OpenChain team.

License

MIT

About

CLI wrapper for abi-guesser from Samczsum

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Generated from SpreadSolvers/ts-template