# submitCommit

> **submitCommit**(`client`, `options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/sp/namespaces/addpiecesapirequest/type-aliases/outputtype/)\>

Defined in: [packages/synapse-core/src/sp/commit.ts:384](https://github.com/FilOzone/synapse-sdk/blob/5989c4b03ed2fe4cf8b1ef29efe1d4ff1ad4c7bc/packages/synapse-core/src/sp/commit.ts#L384)

Send a commit from [prepareAddPieces](/reference/filoz/synapse-core/sp/functions/prepareaddpieces/) or [prepareCreateDataSetAndAddPieces](/reference/filoz/synapse-core/sp/functions/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](/reference/filoz/synapse-core/errors/classes/zodvalidationerror/) before any request is
sent. If nothing landed, sending the same commit again is safe.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `client` | `Client`\<`Transport`, `Chain`\> | The client whose chain sets the default record keeper. |
| `options` | [`OptionsType`](/reference/filoz/synapse-core/sp/namespaces/submitcommit/type-aliases/optionstype/) | [submitCommit.OptionsType](/reference/filoz/synapse-core/sp/namespaces/submitcommit/type-aliases/optionstype/) |

## Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/sp/namespaces/addpiecesapirequest/type-aliases/outputtype/)\>

Hash, extra data and piece count [submitCommit.OutputType](/reference/filoz/synapse-core/sp/namespaces/submitcommit/type-aliases/outputtype/)

## Example

```ts
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)
```

## Throws

Errors [submitCommit.ErrorType](/reference/filoz/synapse-core/sp/namespaces/submitcommit/type-aliases/errortype/)