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

# createIgamingMutations()

> **createIgamingMutations**(`igaming`): [`IgamingMutations`](../interfaces/IgamingMutations.md)

Creates the iGaming mutations: one per write method, with the same name as the method
(`m.loyalty.redeem()`). 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):

* `bonus.optIn/claim/redeemPromoCode` → `bonus` and `wallet` (the core's balance);
* `loyalty.redeem` → `loyalty` and `wallet`; `referrals.register` → `referrals`;
* `casino.launchGame` → `casino.listSessions`; `bonus.resolvePromoCode` and
  `sportsbook.createSession` → nothing.

`mutationKey` is `['enginex', namespace, method]`, without the input. The ones that send `Idempotency-Key`
(`bonus.optIn/claim/redeemPromoCode`, `loyalty.redeem`) reuse the 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 (see the core's `createMutations`), and accept `{ idempotencyKey }` on the factory. The
ones that carry credentials in the input or the result (promo code, game URL, sportsbook
session) have `gcTime: 0`.

## Parameters

### igaming

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

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

## Returns

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

## Example

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

const m = createIgamingMutations(igaming)
const redeem = m.loyalty.redeem()
const result = await redeem.mutationFn({ points: 500, redemptionType: 'bonus' })
for (const queryKey of redeem.invalidates({ points: 500, redemptionType: 'bonus' }, result)) {
  await queryClient.invalidateQueries({ queryKey })
}
```

## Throws

`CONFIGURATION_ERROR` if `igaming` did not come from `createIgaming`.
