Try it Live
Run Blob examples in the interactive playground
Usage
Before Blob Operations
Type Guard Pattern
See Also
- from - Constructor with validation
- isValidVersion - Validate versioned hash
Check if data is valid blob (exactly 131,072 bytes)
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);
}
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
Was this page helpful?
Suggestions