Generate batch inbox addresses for L2 chains using chainId.
This tool implements the batch inbox address generation algorithm used in Optimism-based L2 chains:
bytes32 hash = keccak256(abi.encodePacked(bytes32(uint256(chainId))));
address = prefix + hash[:19]The batch inbox address is derived by:
- Converting the chainId to bytes32
- Computing the keccak256 hash
- Taking the first 19 bytes of the hash
- Prepending a version byte (default:
0x00)
- Node.js v14+ and npm
# Clone the repository
git clone <your-repo-url>
cd l2-inbox-generator
# Install dependencies
npm install# Generate address for chainId with default prefix (0x00)
node src/batch-inbox-address.js <chainId>
# Example
node src/batch-inbox-address.js 11235# Generate address with custom prefix
node src/batch-inbox-address.js <chainId> <prefix>
# Example: use 0xff prefix for demo/testing
node src/batch-inbox-address.js 64322 0xff# Run without arguments to see test cases
node src/batch-inbox-address.jsnode src/batch-inbox-address.js 11235Output:
ChainId: 11235
ChainId as bytes32: 0x0000000000000000000000000000000000000000000000000000000000002be3
Hash: 0x67d742c6fbc30dcb0c4479ba88615dd7d5a2d9dc884d9178f506a055b4a9ccd9
Hash[:19]: 0x67d742c6fbc30dcb0c4479ba88615dd7d5a2d9dc88
Batch Inbox Address: 0x0067d742c6fbc30dcb0c4479ba88615dd7d5a2d9dc88
node src/batch-inbox-address.js 64322 0xffOutput:
ChainId: 64322
ChainId as bytes32: 0x000000000000000000000000000000000000000000000000000000000000fb42
Hash: 0x3108624ddfd2f18f41fb62ccbbcdc3b1d6e39ffbcbcce942cf184d0c807b2b02
Hash[:19]: 0x3108624ddfd2f18f41fb62ccbbcdc3b1d6e39ffbcb
Batch Inbox Address: 0xff3108624ddfd2f18f41fb62ccbbcdc3b1d6e39ffbcb
You can export the generated address as an environment variable:
# Generate and export (requires parsing the output)
export GS_BATCH_INBOX_ADDRESS=0xff3108624ddfd2f18f41fb62ccbbcdc3b1d6e39ffbcb
# Or use in a script
BATCH_INBOX=$(node src/batch-inbox-address.js 64322 0xff | grep "Batch Inbox Address:" | awk '{print $4}')
export GS_BATCH_INBOX_ADDRESS=$BATCH_INBOXThe script includes built-in verification for known test cases:
| ChainId | Expected Hash | Expected Address (0x00 prefix) |
|---|---|---|
| 11235 | 67d742c6... |
0x0067d742c6fbc30dcb0c4479ba88615dd7d5a2d9dc88 |
| 64322 | 3108624d... |
0x003108624ddfd2f18f41fb62ccbbcdc3b1d6e39ffbcb |
l2-inbox-generator/
├── src/
│ └── batch-inbox-address.js # Main script
├── node_modules/ # Dependencies (gitignored)
├── .gitignore
├── package.json
├── package-lock.json
└── README.md
The script supports both ethers.js v5 and v6. Your current installation uses ethers v6.15.0, which should work correctly.
If you encounter issues:
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm installMake sure you're in the project root and dependencies are installed:
npm install- Input: ChainId (uint256)
- Step 1: Convert chainId to bytes32 format (left-padded with zeros)
- Step 2: Compute keccak256 hash of the bytes32 value
- Step 3: Extract first 19 bytes from the hash
- Step 4: Prepend version byte (typically
0x00for production,0xfffor demo) - Output: 20-byte Ethereum address
0x00- Production/mainnet (default)0xff- Demo/testing environment
The script automatically detects and supports both ethers.js v5 and v6:
- Current installation: ethers v6.15.0
- Uses
ethers.zeroPadValue,ethers.toBeHex, andethers.keccak256for v6 - Falls back to
ethers.utils.*methods for v5
ethers: ^6.15.0 - Ethereum library for cryptographic functions
ISC