---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk-predictions/query/functions/createPredictionsMutations.md
---
[Reference](../../../../index.md) / [@getenginex/sdk-predictions/query](../index.md) / createPredictionsMutations

# createPredictionsMutations()

> **createPredictionsMutations**(`predictions`): [`PredictionsMutations`](../interfaces/PredictionsMutations.md)

Creates the mutations for prediction markets: one per write method, with the same name as the method
(`m.orders.place()`). Each call returns `{ mutationKey, mutationFn, invalidates }`, compatible with
TanStack Query v5's `useMutation`; `invalidates(input, result)` lists the prefixes the write leaves
stale (with the session's `userId` at call time; call it only after success):

* `orders.place/placeBatch/cancel/amend` → `orders`, `portfolio` and `wallet` (the core's balance);
* `comments.create/like/unlike` → `comments.list` (of any market) and `comments.listMine`.

`mutationKey` is `['enginex', namespace, method]`, without the input. `orders.place` reuses the
`Idempotency-Key` only after an ambiguous failure (network, timeout, 5xx, `KEY_IN_USE` or
`VALIDATION_ERROR` after a 2xx) with the same input, on this options object (TanStack's retry and a
"try again" do not duplicate the order), and accepts `{ idempotencyKey }` on the factory; `orders.placeBatch`
generates each order's `idempotencyKey` (the ones the app provided are kept; the batch has no single key)
and reuses them, on this `createPredictionsMutations` result, while the batch content (without the
app's keys) is the same and it has not succeeded: after an ambiguous failure and after a partial success (some
`results[i].success === false`) resending the same batch does not repeat the orders that already went through. Total
success, an unambiguous error (the other 4xx) or different content generate new keys. Each send closes only its
own attempt. The batch has no mutation symbol: the attempt lives on this result (in
`sdk-react`, memoized by `useEnginexMutations`, so it survives re-renders) and is shared by
every `orders.placeBatch()` of it; two components that send the same batch after an ambiguous failure use
the same keys.
`cancel`, `amend` and the comments send no key.

## Parameters

### predictions

[`PredictionsClient`](../../interfaces/PredictionsClient.md)

The object returned by `createPredictions(enginex)` (the object itself, not a copy).

## Returns

[`PredictionsMutations`](../interfaces/PredictionsMutations.md)

## Example

```ts
import { useMutation } from '@tanstack/react-query'
import { createPredictionsMutations } from '@getenginex/sdk-predictions/query'

const m = createPredictionsMutations(predictions)
const place = m.orders.place()
const input = { marketId: 'mkt-1', side: 'yes', direction: 'buy', price: 40, quantity: 10 } as const
const order = await place.mutationFn(input)
for (const queryKey of place.invalidates(input, order)) {
  await queryClient.invalidateQueries({ queryKey })
}
```

## Throws

`CONFIGURATION_ERROR` if `predictions` did not come from `createPredictions`.
