|
| 1 | +# abi2human |
| 2 | + |
| 3 | +A zero-dependency Rust implementation for converting Ethereum ABI to human-readable format. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🚀 **Zero Dependencies**: Pure Rust implementation with no external dependencies |
| 8 | +- 📝 **Human-Readable Output**: Convert complex ABI JSON to readable function signatures |
| 9 | +- 🎯 **Multiple Output Formats**: JSON array, raw text, or compact JSON |
| 10 | +- 📁 **Batch Processing**: Convert single files or entire directories |
| 11 | +- 🧪 **Well Tested**: Comprehensive test suite included |
| 12 | +- ⚡ **Fast**: Optimized Rust performance |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +```bash |
| 17 | +cargo build --release |
| 18 | +``` |
| 19 | + |
| 20 | +The binary will be available at `./target/release/abi2human` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +### Quick ABI Inspection |
| 25 | + |
| 26 | +```bash |
| 27 | +# Output to stdout in JSON format |
| 28 | +abi2human contract.json -o |
| 29 | + |
| 30 | +# Raw text format (one function per line) |
| 31 | +abi2human contract.json -or |
| 32 | + |
| 33 | +# Compact JSON (no pretty printing) |
| 34 | +abi2human contract.json -o --no-pretty |
| 35 | +``` |
| 36 | + |
| 37 | +### File Conversion |
| 38 | + |
| 39 | +```bash |
| 40 | +# Convert and save to a new file |
| 41 | +abi2human input.json output.json |
| 42 | + |
| 43 | +# Convert with custom suffix |
| 44 | +abi2human input.json -s ".readable" |
| 45 | +``` |
| 46 | + |
| 47 | +### Batch Directory Processing |
| 48 | + |
| 49 | +```bash |
| 50 | +# Convert all JSON files in a directory |
| 51 | +abi2human ./abis/ -d ./readable/ |
| 52 | + |
| 53 | +# Filter with pattern |
| 54 | +abi2human ./abis/ -d ./readable/ -p "*.abi.json" |
| 55 | +``` |
| 56 | + |
| 57 | +### Command Line Options |
| 58 | + |
| 59 | +``` |
| 60 | +OPTIONS: |
| 61 | + -o, --stdout Output to stdout |
| 62 | + -r, --raw Output raw text format instead of JSON |
| 63 | + -h, --help Show help message |
| 64 | + -v, --version Show version |
| 65 | + -q, --quiet Suppress non-output messages |
| 66 | + -d, --dir Process directory |
| 67 | + -p, --pattern Glob pattern for filtering files |
| 68 | + -s, --suffix Custom suffix for output files (default: ".readable") |
| 69 | + --no-pretty Disable pretty-printing |
| 70 | +``` |
| 71 | + |
| 72 | +## Examples |
| 73 | + |
| 74 | +### ERC20 Token ABI |
| 75 | + |
| 76 | +Input: |
| 77 | +```json |
| 78 | +[ |
| 79 | + { |
| 80 | + "type": "function", |
| 81 | + "name": "transfer", |
| 82 | + "inputs": [ |
| 83 | + {"name": "to", "type": "address"}, |
| 84 | + {"name": "amount", "type": "uint256"} |
| 85 | + ], |
| 86 | + "outputs": [{"type": "bool"}], |
| 87 | + "stateMutability": "nonpayable" |
| 88 | + } |
| 89 | +] |
| 90 | +``` |
| 91 | + |
| 92 | +Output: |
| 93 | +``` |
| 94 | +function transfer(address to, uint256 amount) returns (bool) |
| 95 | +``` |
| 96 | + |
| 97 | +### Event Example |
| 98 | + |
| 99 | +Input: |
| 100 | +```json |
| 101 | +{ |
| 102 | + "type": "event", |
| 103 | + "name": "Transfer", |
| 104 | + "inputs": [ |
| 105 | + {"name": "from", "type": "address", "indexed": true}, |
| 106 | + {"name": "to", "type": "address", "indexed": true}, |
| 107 | + {"name": "value", "type": "uint256", "indexed": false} |
| 108 | + ] |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +Output: |
| 113 | +``` |
| 114 | +event Transfer(address indexed from, address indexed to, uint256 value) |
| 115 | +``` |
| 116 | + |
| 117 | +## Supported ABI Types |
| 118 | + |
| 119 | +- ✅ Functions (view, pure, payable, nonpayable) |
| 120 | +- ✅ Events (with indexed parameters) |
| 121 | +- ✅ Constructors |
| 122 | +- ✅ Fallback functions |
| 123 | +- ✅ Receive functions |
| 124 | + |
| 125 | +## Development |
| 126 | + |
| 127 | +### Running Tests |
| 128 | + |
| 129 | +```bash |
| 130 | +cargo test |
| 131 | +``` |
| 132 | + |
| 133 | +### Building |
| 134 | + |
| 135 | +```bash |
| 136 | +# Debug build |
| 137 | +cargo build |
| 138 | + |
| 139 | +# Release build (optimized) |
| 140 | +cargo build --release |
| 141 | +``` |
| 142 | + |
| 143 | +## Architecture |
| 144 | + |
| 145 | +The project is organized into several modules: |
| 146 | + |
| 147 | +- `abi.rs` - ABI data structures and formatting |
| 148 | +- `json_parser.rs` - Custom JSON parser implementation |
| 149 | +- `converter.rs` - Core conversion logic |
| 150 | +- `file_ops.rs` - File and directory operations |
| 151 | +- `main.rs` - CLI entry point and argument parsing |
| 152 | +- `tests.rs` - Unit tests |
| 153 | + |
| 154 | +## Why Zero Dependencies? |
| 155 | + |
| 156 | +This implementation uses no external crates, providing: |
| 157 | + |
| 158 | +- **Security**: No supply chain vulnerabilities from dependencies |
| 159 | +- **Simplicity**: Easy to audit and understand |
| 160 | +- **Portability**: Works anywhere Rust compiles |
| 161 | +- **Stability**: No breaking changes from dependency updates |
| 162 | + |
| 163 | +## License |
| 164 | + |
| 165 | +MIT |
| 166 | + |
| 167 | +## Contributing |
| 168 | + |
| 169 | +Contributions are welcome! Please feel free to submit a Pull Request. |
0 commit comments