Skip to main content

Try it Live

Run Blob examples in the interactive playground

    Usage

    Before Blob Operations

    import { Blob } from 'tevm';
    
    // Validate before expensive operations
    if (Blob.isValid(data)) {
      const commitment = Blob.toCommitment(data);
      const proof = Blob.toProof(data);
    } else {
      // Encode data into blob format
      const blob = Blob.fromData(data);
    }
    

    Type Guard Pattern

    import { Blob, type BrandedBlob } from 'tevm';
    
    function assertBlob(value: Uint8Array): asserts value is BrandedBlob {
      if (!Blob.isValid(value)) {
        throw new Error(`Invalid blob size: ${value.length}`);
      }
    }
    
    // Usage
    const data = new Uint8Array(131072);
    assertBlob(data); // Throws if invalid
    // data is now typed as BrandedBlob
    

    See Also