Skip to content

commitmentToVersionedHash

Transform a commitment to it's versioned hash.

Import

import { commitmentToVersionedHash } from 'viem'

Usage

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

Returns

Hex | ByteArray

Versioned hash corresponding to the commitment.

Parameters

commitment

  • Type: Hex | ByteArray

Commitment to transform into a versioned hash.

const blobs = toBlobs({ data: '0x1234' })
const [commitment] = blobsToCommitments({ blobs, kzg })
const versionedHashes = commitmentToVersionedHash({ 
  commitment,  
})

to

  • Type: "bytes" | "hex"

The output type.

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

version

  • Type: number
  • Default: 1

Version to tag onto the hash. Defaults to 1.

const blobs = toBlobs({ data: '0x1234' })
const [commitment] = blobsToCommitments({ blobs, kzg })
const versionedHashes = commitmentToVersionedHash({ 
  commitment, 
  version: 69, 
})