# prepareCreateDataSetAndAddPieces

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

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

Sign a create data set and add pieces commit and return it as JSON-safe data, without sending it.

Checks the pieces and data set metadata fit in one message first, so a commit that can't be sent fails before it
is saved. Save the commit, then send it with [submitCommit](/reference/filoz/synapse-core/sp/functions/submitcommit/). Resubmitting the same commit can never create
the data set twice: FWSS rejects a reused client data set id.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `client` | `Client`\<`Transport`, `Chain`, `Account`\> | The client that signs the commit. |
| `options` | [`OptionsType`](/reference/filoz/synapse-core/sp/namespaces/preparecreatedatasetandaddpieces/type-aliases/optionstype/) | [prepareCreateDataSetAndAddPieces.OptionsType](/reference/filoz/synapse-core/sp/namespaces/preparecreatedatasetandaddpieces/type-aliases/optionstype/) |

## Returns

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

The signed commit [prepareCreateDataSetAndAddPieces.OutputType](/reference/filoz/synapse-core/sp/namespaces/preparecreatedatasetandaddpieces/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.prepareCreateDataSetAndAddPieces(client, {
  payee: '0x1234567890123456789012345678901234567890', // the provider's service address
  metadata: { project: 'photos' },
  pieces: [{ pieceCid }],
})

// Save the commit before sending it, so it can be resubmitted after a crash.
const saved = JSON.stringify(commit)

const result = await SP.submitCommit(client, { serviceURL, commit: JSON.parse(saved) })
const { dataSetId, pieceIds } = await SP.waitForCreateDataSetAddPieces({ client, ...result })
console.log(dataSetId, pieceIds)
```

## Throws

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