A simple TypeScript example demonstrating how to send EIP-4844 blob transactions using ethers.js v6 and KZG commitments.
- EIP-4844 Ethers Example
- Node.js >= 20
- npm or yarn
- A funded Sepolia wallet (for testing)
- Basic knowledge of TypeScript/JavaScript
npm install
cp .env.example .env
# Edit .env with your PRIVATE_KEY
npm run blob
# Or with a contract call
npm run blob-contractEIP-4844 blob transactions (Type 3) allow attaching large data blobs (up to 131,072 bytes) to transactions at lower cost than calldata. Blobs are stored separately and pruned after ~18 days.
This repository contains two examples:
send-blob.ts- Simple blob transaction without contract interactionsend-blob-contract.ts- Blob transaction with contract function call
Create .env file:
PRIVATE_KEY=0x1234567890abcdef...
RPC_URL=https://1rpc.io/sepoliaPRIVATE_KEY: Required - your wallet's private keyRPC_URL: Optional - defaults to Sepolia testnet if not provided
npm run blobSends a blob transaction without contract interaction.
npm run blob-contractSends a blob transaction and calls the shout(string) function on the contract at 0x7bef193Df28Cd0B164A7227a7904Cdac09f9A1ef with the text "ethers-example".
Simple blob transaction:
🚀 Sending blob transaction...
Blob data: "Blob vibes only 🌈"
Transaction sent: 0xabc123...
Waiting for confirmation...
✅ Transaction confirmed!
Block: 123456
Status: Success
Blob Versioned Hashes: 0xdef456...
Blobscan: https://sepolia.blobscan.com/blob/0xdef456...
Blob transaction with contract call:
🚀 Sending blob transaction with contract call...
Blob data: "Blob vibes only 🌈"
Contract: 0x7bef193Df28Cd0B164A7227a7904Cdac09f9A1ef
Function: shout("ethers-example")
Transaction sent: 0xabc123...
Waiting for confirmation...
✅ Transaction confirmed!
Block: 123456
Status: Success
Blob Versioned Hashes: 0xdef456...
Blobscan: https://sepolia.blobscan.com/blob/0xdef456...
Etherscan: https://sepolia.etherscan.io/tx/0xabc123...
Working public RPC endpoints for Sepolia (blob transaction support):
https://1rpc.io/sepoliahttps://ethereum-sepolia-rpc.publicnode.comhttps://eth-sepolia.api.onfinality.io/publichttps://0xrpc.io/sephttps://sepolia.infura.io/v3/YOUR_API_KEY(requires account)
EIP-4844 introduces Type 3 transactions that attach "blobs" of data:
- Stored separately in blob space (not in transaction calldata)
- Cheaper for large data (up to 131,072 bytes per blob)
- Pruned after ~18 days (Epoch 4096)
- Verifiable using KZG polynomial commitments
KZG (Kate-Zaverucha-Goldberg) commitments provide:
- Commitment to blob data without revealing it
- Proof that blob matches commitment
- Efficient verification (constant time, 48-byte proofs)
In this script:
kzg.blobToKZGCommitment(blobHex)- Creates commitmentkzg.computeBlobKZGProof(blobHex, commitmentHex)- Generates proof- Versioned hash:
0x01+ first 31 bytes of SHA-256(commitment)
The blob versioned hash is derived from the KZG commitment and is used to reference blobs on-chain. It allows explorers like BlobScan to locate and verify blob data attached to a transaction. Each blob attached to a transaction has a unique versioned hash.
{
type: 3,
to: address,
data: '0x...',
maxFeePerGas: bigint,
maxPriorityFeePerGas: bigint,
maxFeePerBlobGas: bigint,
blobs: [{
data: Uint8Array, // 131,072 bytes
commitment: Uint8Array, // 48 bytes
proof: Uint8Array // 48 bytes
}],
kzg: KZG
}Limits:
- Up to 6 blobs per transaction
- Each blob exactly 131,072 bytes (padded with zeros if smaller)
Simple blob transaction (send-blob.ts):
- Blob Preparation: Creates 131,072-byte buffer, fills with UTF-8 message
- KZG Operations: Computes commitment and proof using
kzg-wasm - Transaction: Uses ethers v6
sendTransaction()with blob support - Versioned Hashes: Automatically computed by ethers from commitments
Blob transaction with contract call (send-blob-contract.ts):
- Blob Preparation: Same as above
- KZG Operations: Same as above
- Contract Call Encoding: Encodes function call using
Interface.encodeFunctionData() - Transaction: Sends blob transaction with
datafield containing encoded function call - Output: Includes both Blobscan and Etherscan links for viewing blob and contract interaction
ethers@^6.16.0- Ethereum library with blob transaction supportkzg-wasm@^1.0.0- WebAssembly KZG commitment librarydotenv@^17.2.3- Environment variable loadertsx@^4.21.0- TypeScript executor
MIT