/
v3.0.11Get access

Casino call

Calls a Casino method through one interface, whether it is served by the CMS over HTTP or by Swarm over the WebSocket. The hook picks the right transport for you and returns the same shape either way.

Show as
Import from@softconstruct/betchain-core-client/hooks
Use it whenGame catalogs, providers, jackpot pools and tournament leaderboards.

Signature

.ts
useCasino(functionRef: TFn, options: {
  params?: ParamsOfFunction<TFn>;
  dependencies?: DependencyList;
  shouldWait?: boolean;
  successCallback?: (data?: ResponseOfFn<TFn>) => void;
}): {
  data; status; message; hasError; isLoading; makeRequest;
}

Options

Passed as the second argument, except for useInitSDK which takes a single config object.

NameTypeRequiredDescription
paramsParamsOfFunction<TFn>NoArguments forwarded to the method. Defaults to an empty object. Typed from the method you pass in.
dependenciesDependencyListNoValues that re-trigger the call when they change, like a useEffect dependency array. Defaults to an empty array, so the call runs once.
shouldWaitbooleanNoWhen true the hook does not fire on mount. Use it to defer a call until a prerequisite (an id, a logged-in session) is ready. Defaults to false.
successCallback(data?: ResponseOfFn<TFn>) => voidNoInvoked with the response after a successful call.

Returns

NameTypeRequiredDescription
dataResponseOfFn<TFn>NoThe response payload. An empty object until the first call resolves.
isLoadingbooleanNoTrue while a call is in flight.
hasErrorbooleanNoTrue when the last call failed.
messagestringNoError text for the last failure, empty otherwise.
statusLOADING | LOADED | FAILEDNoThe raw request status, if you need more than isLoading.
makeRequest(overrideParams?) => Promise<Result>NoRuns the call on demand, optionally with different params. Useful together with shouldWait.

Example

.ts
1import {2  getCasinoGames3} from '@softconstruct/betchain-core-client/casino';4import {5  useCasino6} from '@softconstruct/betchain-core-client/hooks';7 8const {9  data,10  isLoading,11  hasError,12  message13} = useCasino(getCasinoGames, {14  params: {15    limit: 2016  },17  dependencies: []18});

Notes

Two transports, one hookCMS-backed methods go over HTTP, the rest go through the Swarm session. That is why the Casino SDK lists both WebSocket and HTTP.
Was this page helpful?