Skip to content

commitmentsToVersionedHashes

Transform a list of commitments to their versioned hashes.

Import

import { commitmentsToVersionedHashes } from 'viem'

Usage

example.ts
import { 
  blobsToCommitments, 
  commitmentsToVersionedHashes, 
  toBlobs 
} from 'viem'
import { kzg } from './kzg'
 
const blobs = toBlobs({ data: '0x1234' })
const commitments = blobsToCommitments({ blobs, kzg })
const versionedHashes = commitmentsToVersionedHashes({  
  commitments,  
}) 

Returns

Hex[] | ByteArray[]

List of versioned hashes corresponding to the input commitments.

Parameters

commitments

  • Type: Hex[] | ByteArray[]

List of commitments to transform into versioned hashes.

const blobs = toBlobs({ data: '0x1234' })
const commitments = blobsToCommitments({ blobs, kzg })
const versionedHashes = commitmentsToVersionedHashes({ 
  commitments,  
  kzg, 
})

to

  • Type: "bytes" | "hex"

The output type.

const blobs = toBlobs({ data: '0x1234' })
const commitments = blobsToCommitments({ blobs, kzg })
const versionedHashes = commitmentsToVersionedHashes({ 
  commitments, 
  to: 'bytes'
})
const versionedHashes: readonly ByteArray[]
versionedHashes

version

  • Type: number
  • Default: 1

Version to tag onto the hashes. Defaults to 1.

const blobs = toBlobs({ data: '0x1234' })
const commitments = blobsToCommitments({ blobs, kzg })
const versionedHashes = commitmentsToVersionedHashes({ 
  commitments, 
  version: 69, 
})