Skip to content

submitCommit

submitCommit(client, options): Promise<OutputType>

Defined in: packages/synapse-core/src/sp/commit.ts:384

Send a commit from prepareAddPieces or prepareCreateDataSetAndAddPieces to the PDP API.

The commit carries everything the request needs, so it can be loaded from storage after a crash and sent as is. It is validated first, so a corrupted or edited commit throws ZodValidationError before any request is sent. If nothing landed, sending the same commit again is safe.

Parameter Type Description
client Client<Transport, Chain> The client whose chain sets the default record keeper.
options OptionsType submitCommit.OptionsType

Promise<OutputType>

Hash, extra data and piece count submitCommit.OutputType

import * as SP from '@filoz/synapse-core/sp'
import * as Piece from '@filoz/synapse-core/piece'
import { calibration } from '@filoz/synapse-core/chains'
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'

const client = createWalletClient({
  account: privateKeyToAccount('0x...'),
  chain: calibration,
  transport: http(),
})
const serviceURL = 'https://pdp.example.com'
const pieceCid = Piece.from('bafkzcibcaabffs4jcd4iheeo5wisbmurjb7l4xgpmzgyzrenebvjjhsbwgx4smy')

const commit = await SP.prepareAddPieces(client, { dataSetId: 1n, clientDataSetId: 1n, pieces: [{ pieceCid }] })
const saved = JSON.stringify(commit)

// After a restart, load the saved commit and send it. Resending it is safe if nothing landed.
const loaded: SP.Commit = JSON.parse(saved)
const result = await SP.submitCommit(client, { serviceURL, commit: loaded })
console.log(result.txHash)

Errors submitCommit.ErrorType