setupKzg
Sets up and defines a EIP-4844 compatible KZG interface. The KZG interface is used in the blob transaction signing process to generate KZG commitments & proofs.
setupKzg
accepts a KZG interface that implements three functions:
loadTrustedSetup
: A function to initialize the KZG trusted setup.blobToKzgCommitment
: A function that takes a blob and returns it's KZG commitment.computeBlobKzgProof
: A function that takes a blob and it's commitment, and returns the KZG proof.
A couple of KZG implementations we recommend are:
Import
import { setupKzg } from 'viem'
Usage
import * as cKzg from 'c-kzg'
import { setupKzg } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'
const kzg = setupKzg(cKzg, mainnetTrustedSetupPath)
Trusted Setups
As seen above, when you set up your KZG interface, you will need to provide a trusted setup file. You can either import a trusted setup via the viem/node
entrypoint (if you're using an engine that supports Node.js' node:fs
module), or you can directly import the trusted setup .json
via the viem/trusted-setups
entrypoint.
Viem exports the following trusted setups:
mainnet.json
: For Ethereum Mainnet & it's Testnets (Sepolia, Goerli, etc).minimal.json
: For low-resource local dev testnets, and spec-testing.
The trusted setup files are retrieved from the Ethereum consensus-specs repository.
viem/node
Entrypoint
Viem exports paths to the trusted setup via the viem/node
entrypoint, designed to be used with setupKzg
.
import {
mainnetTrustedSetupPath,
minimalTrustedSetupPath,
} from 'viem/node'
viem/trusted-setups
Entrypoint
Alternatively, you can directly import the contents of the trusted setup file from the viem/trusted-setups
entrypoint.
import mainnetTrustedSetup from 'viem/trusted-setups/mainnet.json'
import minimalTrustedSetup from 'viem/trusted-setups/minimal.json'
Returns
Kzg
The KZG interface.
Parameters
kzg
- Type:
Kzg & { loadTrustedSetup(path: string): void }
The EIP-4844 compatible KZG interface.
import * as cKzg from 'c-kzg'
import { setupKzg } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'
const kzg = setupKzg(
cKzg,
mainnetTrustedSetupPath
)
path
- Type:
string
The path to the trusted setup file.
import * as cKzg from 'c-kzg'
import { setupKzg } from 'viem'
import { mainnetTrustedSetupPath } from 'viem/node'
const kzg = setupKzg(
cKzg,
mainnetTrustedSetupPath
)