toBlobSidecars
Transforms arbitrary data (or blobs, commitments, & proofs) into a blob sidecar array.
Import
import { toBlobSidecars } from 'viem'
Usage
With Arbitrary Data
You can generate blob sidecars from arbitrary data without having to compute the blobs, commitments, and proofs first (that's done internally).
example.ts
import { toBlobSidecars } from 'viem'
import { kzg } from './kzg'
const sidecars = toBlobSidecars({ data: '0x...', kzg })
With Blobs, Commitments, and Proofs
Alternatively, you can reach for the lower-level API and insert the blobs, commitments, and proofs directly.
example.ts
import {
blobsToCommitments,
blobsToProofs,
toBlobSidecars,
toBlobs
} from 'viem'
import { kzg } from './kzg'
const blobs = toBlobs({ data: '0x...' })
const commitments = blobsToCommitments({ blobs, kzg })
const proofs = blobsToProofs({ blobs, commitments, kzg })
const sidecars = toBlobSidecars({ blobs, commitments, proofs })
Returns
BlobSidecars
Blob sidecars from the input data.
Parameters
blobs
- Type:
Hex[] | ByteArray[]
Blobs to transform into blob sidecars.
import {
blobsToCommitments,
blobsToProofs,
toBlobSidecars,
toBlobs
} from 'viem'
import { kzg } from './kzg'
const blobs = toBlobs({ data: '0x...' })
const commitments = blobsToCommitments({ blobs, kzg })
const proofs = blobsToProofs({ blobs, commitments, kzg })
const sidecars = toBlobSidecars({
blobs,
commitments,
proofs,
})
commitments
- Type:
Hex[] | ByteArray[]
Commitments corresponding to the input blobs.
import {
blobsToCommitments,
blobsToProofs,
toBlobSidecars,
toBlobs
} from 'viem'
import { kzg } from './kzg'
const blobs = toBlobs({ data: '0x...' })
const commitments = blobsToCommitments({ blobs, kzg })
const proofs = blobsToProofs({ blobs, commitments, kzg })
const sidecars = toBlobSidecars({
blobs,
commitments,
proofs,
})
data
- Type:
Hex | ByteArray
Data to transform into blob sidecars.
import { toBlobSidecars } from 'viem'
import { kzg } from './kzg'
const sidecars = toBlobSidecars({
data: '0x...',
kzg,
})
kzg
- Type:
KZG
KZG implementation. See setupKzg
for more information.
import * as kzg from 'c-kzg'
import { toBlobSidecars, setupKzg } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'
const kzg = setupKzg(cKzg, mainnetTrustedSetupPath)
const sidecars = toBlobSidecars({
data: '0x...',
kzg,
})
proofs
- Type:
Hex[] | ByteArray[]
Proofs corresponding to the input blobs.
import {
blobsToCommitments,
blobsToProofs,
toBlobSidecars,
toBlobs
} from 'viem'
import { kzg } from './kzg'
const blobs = toBlobs({ data: '0x...' })
const commitments = blobsToCommitments({ blobs, kzg })
const proofs = blobsToProofs({ blobs, commitments, kzg })
const sidecars = toBlobSidecars({
blobs,
commitments,
proofs,
})
to
- Type:
"bytes" | "hex"
The output type.
import { toBlobSidecars, toBlobs } from 'viem'
const sidecars = toBlobSidecars({
data: '0x1234',
kzg,
to: 'bytes',
})
const sidecars: BlobSidecars<ByteArray>sidecars