Extract original data from blob (reads length prefix)
fromData()
┌─────────────────┬──────────────┬─────────────┐ │ Length (8 B) │ Data (N B) │ Padding │ ├─────────────────┼──────────────┼─────────────┤ │ Little-endian │ Original │ Zero bytes │ │ uint64 │ data │ │ └─────────────────┴──────────────┴─────────────┘ Bytes 0-7 Bytes 8-N Bytes N+1-131071 Total: 131,072 bytes (Blob.SIZE)
import { Blob } from 'tevm'; const blob = Blob.fromData(new TextEncoder().encode("test")); // Manual extraction (equivalent to toData()) const view = new DataView(blob.buffer, blob.byteOffset); const length = Number(view.getBigUint64(0, true)); // Little-endian const data = blob.slice(8, 8 + length); console.log(length); // 4 console.log(new TextDecoder().decode(data)); // "test"
Was this page helpful?