Skip to main content

Documentation Index

Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt

Use this file to discover all available pages before exploring further.

Try it Live

Run Blob examples in the interactive playground
New to blobs? Start with Fundamentals for guided examples and EIP-4844 concepts.

Type Definition

Branded Uint8Array representing EIP-4844 blob data (exactly 131,072 bytes = 128 KB).
export type BrandedBlob = Uint8Array & { readonly __blob: unique symbol };
Blobs enable proto-danksharding (EIP-4844), providing temporary data availability for L2 rollups at significantly lower gas costs compared to calldata.
// KZG commitment (48 bytes)
export type Commitment = Uint8Array & { readonly __commitment: unique symbol };

// KZG proof (48 bytes)
export type Proof = Uint8Array & { readonly __proof: unique symbol };

// Versioned hash (32 bytes) - commitment hash with version prefix
export type VersionedHash = Uint8Array & { readonly __versionedHash: unique symbol };

Constants

Blob.SIZE                      // 131072 bytes (128 KB)
Blob.FIELD_ELEMENTS_PER_BLOB   // 4096 field elements
Blob.BYTES_PER_FIELD_ELEMENT   // 32 bytes per element
Blob.MAX_PER_TRANSACTION       // 6 blobs maximum
Blob.COMMITMENT_VERSION_KZG    // 0x01 version byte
Blob.GAS_PER_BLOB             // 131072 (2^17)
Blob.TARGET_GAS_PER_BLOCK     // 393216 (3 blobs)

API Methods

Constructors

  • from - Universal constructor from any input (auto-encodes if needed)
  • fromData - Encode arbitrary data into blob format with length prefix

Data Encoding/Decoding

  • toData - Extract original data from blob (reads length prefix)
  • splitData - Split large data into multiple blobs
  • joinData - Join data from multiple blobs

KZG Cryptography

  • toCommitment - Compute 48-byte KZG commitment for blob
  • toProof - Generate 48-byte KZG proof
  • toVersionedHash - Compute versioned hash (0x01 + SHA256 of commitment)
  • verify - Verify KZG proof for blob and commitment
  • verifyBatch - Batch verify multiple blob proofs

Validation

  • isValid - Check if data is valid blob (exactly 131,072 bytes)
  • isValidVersion - Validate versioned hash format and version byte

Gas Estimation

Nested Namespaces

Types

export type BrandedBlob = Uint8Array & {
  readonly __blob: unique symbol;
};
Main blob type. Exactly 131,072 bytes (128 KB) containing 4,096 field elements of 32 bytes each.

Usage Patterns

Creating Blobs from Data

import { Blob } from 'tevm';

// Small data - single blob
const data = new TextEncoder().encode("Rollup batch #1234");
const blob = Blob.fromData(data);

console.log(`Data size: ${data.length} bytes`);
console.log(`Blob size: ${blob.length} bytes`); // Always 131,072

// Extract original data
const decoded = Blob.toData(blob);
console.log(new TextDecoder().decode(decoded)); // "Rollup batch #1234"

Handling Large Data

import { Blob } from 'tevm';

// Large data spanning multiple blobs
const largeData = new Uint8Array(300_000); // 300 KB

// Estimate blobs needed
const blobCount = Blob.estimateBlobCount(largeData);
console.log(`Requires ${blobCount} blobs`); // 3 blobs

// Split into blobs
const blobs = Blob.splitData(largeData);
console.log(`Created ${blobs.length} blobs`);

// Later: join data back
const reconstructed = Blob.joinData(blobs);
console.log(`Reconstructed ${reconstructed.length} bytes`);

Versioned Hashes for Transactions

import { Kzg, Blob } from 'tevm';

// Create blob and get versioned hash
const blob = Blob.fromData(data);
const commitment = Kzg.Commitment(blob);
const versionedHash = Blob.toVersionedHash(commitment);

// Use in EIP-4844 transaction
const tx = {
  type: '0x03', // EIP-4844 type
  blobVersionedHashes: [versionedHash],
  maxFeePerBlobGas: 1000000n,
  // ... other fields
};

// Validate versioned hash
console.log(Blob.isValidVersion(versionedHash)); // true
console.log(Blob.VersionedHash.getVersion(versionedHash)); // 1

Gas Cost Estimation

import { Blob } from 'tevm';

// Calculate gas cost for blob transaction
const blobBaseFee = 50000000n; // 50 gwei (example)
const blobCount = 2;

const blobGas = Blob.calculateGas(blobCount, blobBaseFee);
console.log(`Blob gas cost: ${blobGas} wei`);

// Compare with calldata cost
const calldataBytes = 131072 * 2; // 2 blobs worth
const calldataGas = calldataBytes * 16n; // 16 gas per byte
console.log(`Calldata gas cost: ${calldataGas} wei`);
console.log(`Savings: ${((1 - Number(blobGas) / Number(calldataGas)) * 100).toFixed(1)}%`);

Batch Verification

import { Kzg } from 'tevm';

// Multiple blobs with commitments and proofs
const blobs = [blob1, blob2, blob3];
const commitments = blobs.map(b => Kzg.Commitment(b));
const proofs = blobs.map(b => Kzg.Proof(b));

// Verify all at once (more efficient)
const allValid = Kzg.verifyBatch(blobs, commitments, proofs);

if (!allValid) {
  // Fall back to individual verification to find invalid blob
  for (let i = 0; i < blobs.length; i++) {
    const valid = Kzg.verify(blobs[i], commitments[i], proofs[i]);
    if (!valid) {
      console.error(`Blob ${i} failed verification`);
    }
  }
}

Tree-Shaking

Import only what you need for optimal bundle size:
// Import specific functions (tree-shakeable)
import { fromData, toData, estimateBlobCount } from 'tevm/BrandedBlob';

const blob = fromData(data);
const decoded = toData(blob);
const count = estimateBlobCount(largeData);

// Only these 3 functions included in bundle

Core Documentation

  • Fundamentals - EIP-4844 blob structure and proto-danksharding
  • EIP-4844 - Detailed EIP-4844 specification coverage
  • KZG - KZG commitment scheme explanation

Advanced Features

  • Usage Patterns - Real-world blob transaction examples
  • WASM - WASM acceleration for KZG operations
  • Transaction - EIP-4844 transaction type (0x03)
  • Keccak256 - SHA256 and keccak256 hashing for commitments
  • Hex - Hex encoding for versioned hashes

Specification