Skip to content

s3bc40/txdecode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” txdecode

A blazingly fast EVM transaction decoder CLI built in Rust, powered exclusively by Alloy.

Decode any Ethereum transaction or raw calldata into human-readable function calls and parameters β€” no more squinting at hex blobs.

txdecode demo


✨ Features

  • πŸš€ Automatic function signature detection via 4byte.directory
  • 🎯 Smart collision handling β€” prioritizes well-known ERC-20/ERC-721 functions over scam signatures
  • 🌐 Multi-chain support β€” works on Ethereum, Arbitrum, Base, Optimism, Polygon, and any EVM chain
  • πŸ”— Automatic chain detection β€” fetches chain ID from RPC endpoint
  • πŸ“¦ Etherscan ABI fallback β€” fetches verified contract ABIs when 4byte lookup fails
  • πŸ’Ύ Local ABI cache β€” saves fetched ABIs to ~/.txdecode/cache/ for faster repeated lookups
  • 🎨 Beautiful terminal output β€” color-coded tables with formatted values
  • ⚑ Pure Alloy β€” no legacy dependencies (ethers-rs, web3, etc.)
  • πŸ”’ Type-safe ABI decoding with comprehensive error handling

πŸ“¦ Installation

From source (recommended)

git clone https://github.com/s3bc40/txdecode.git
cd txdecode
cargo build --release
sudo cp target/release/txdecode /usr/local/bin/

🎯 Usage

Decode a transaction by hash

# Using default RPC (ethereum-rpc.publicnode.com)
txdecode 0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060

# Using custom RPC endpoint
txdecode --rpc https://eth.llamarpc.com 0x5c504ed...

Decode raw calldata

txdecode --input 0xa9059cbb0000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f0beb00000000000000000000000000000000000000000000000000000000000f4240

Use Etherscan fallback for custom contracts

# Set API key via environment variable
export ETHERSCAN_API_KEY="your_api_key_here"
txdecode 0x1234...abcd

# Or pass it directly
txdecode --etherscan-key YOUR_KEY 0x1234...abcd

Show help

txdecode --help

Multi-chain support (auto-detects chain ID)

# Arbitrum
txdecode --rpc https://arb1.arbitrum.io/rpc 0x9368b9...

# Base
txdecode --rpc https://base.drpc.org 0x9b96d6...

# Optimism
txdecode --rpc https://mainnet.optimism.io 0xabc...

πŸ› οΈ Tech Stack

Component Library
Ethereum types alloy::primitives
ABI encoding/decoding alloy::sol_types, alloy_json_abi
RPC provider alloy::providers
HTTP client reqwest
Error handling color-eyre
CLI parsing clap v4
Pretty tables comfy-table

πŸ§ͺ Example Output

Simple ETH transfer


πŸ“‘ Fetched transaction: 0x9de987763c97291e54d9a3aae7c985f1dabbc794e556931f045586ca9af8ca95
From: 0x396343362be2a4da1ce0c1c210945346fb82aa49
To: 0xe688b84b23f322a994a53dbf8e15fa82cdb71127
Value: 11445027713806579 wei

ℹ️ No calldata to decode (empty input).

ERC-20 transfer


πŸ“‘ Fetched transaction: 0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060
From: 0xa9d1e08c7793af67e9d92fe308d5697fb81d3e43
To: 0x27054b13b1b798b345b591a4d22e6562d47ea75a
Value: 0 wei

βœ… Function: transfer
+-----------+---------+--------------------------------------------+
| Parameter | Type | Value |
+==================================================================+
| \_to | address | 0x4fd2b3e5e6f4e4a7c1b1c9d0f9d1a3c5e6f4e4a7 |
|-----------+---------+--------------------------------------------|
| \_value | uint256 | 5_000_000_000 (uint256) |
+-----------+---------+--------------------------------------------+

Raw calldata decode


txdecode --input 0xa9059cbb0000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f0beb00000000000000000000000000000000000000000000000000000000000f4240

βœ… Function: transfer
+-----------+---------+--------------------------------------------+
| Parameter | Type | Value |
+==================================================================+
| param0 | address | 0x0742d35cc6634c0532925a3b844bc9e7595f0beb |
|-----------+---------+--------------------------------------------|
| param1 | uint256 | 1_000_000 (uint256) |
+-----------+---------+--------------------------------------------+


πŸ—‚οΈ Project Structure


txdecode/
β”œβ”€β”€ src/
β”‚ └── main.rs # All-in-one implementation (pre-refactor)
β”œβ”€β”€ Cargo.toml # Dependencies and metadata
β”œβ”€β”€ README.md # This file
└── LICENSE # MIT license

Post-refactor structure (coming soon):


src/
β”œβ”€β”€ main.rs # CLI entry point
β”œβ”€β”€ decode.rs # Core decoding logic
β”œβ”€β”€ signatures.rs # 4byte.directory lookups
β”œβ”€β”€ etherscan.rs # Etherscan/Sourcify API
β”œβ”€β”€ cache.rs # Local file cache
└── display.rs # Pretty table formatting


πŸ§ͺ Testing

# Run unit tests
cargo test

# Run with verbose output
cargo test -- --nocapture

# Test specific function
cargo test test_selector_extraction

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Development setup:

git clone https://github.com/s3bc40/txdecode.git
cd txdecode
cargo build
cargo test

πŸ—ΊοΈ Roadmap

Phase 1: Core Functionality βœ…

  • Selector extraction
  • 4byte.directory API integration
  • Dynamic signature parsing
  • Collision-resistant decoding
  • RPC transaction fetching
  • Etherscan ABI fallback
  • Local ABI caching
  • Pretty terminal output

Phase 2: Enhancements πŸ”œ

  • Refactor into clean modules
  • Comprehensive unit tests
  • Multi-chain support (Arbitrum, Base, Optimism, Polygon)
  • CLI flags for custom RPC, Etherscan key

πŸ“„ License

MIT License - see LICENSE file for details


πŸ™ Acknowledgments

  • Alloy β€” The modern, high-performance Ethereum library that powers this tool
  • 4byte.directory β€” Community-maintained function signature database
  • Etherscan β€” Verified contract ABI source

πŸ’¬ Support


Built with ❀️ by s3bc40

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages