API Usage
CoinOp:
The following is the structure of a CoinOp:
interface CoinOp {
amount: number;
choice: string;
createdAt: string;
gameId: string;
gameMode: string;
gameSlug: string;
id: string;
numRounds: number;
status: string;
walletId: string;
depositTxn?: string;
winAmounts?: number[];
bonusRounds?: number;
rolledItems?: any;
won?: boolean;
resultTxn?: string;
}
interface Payload {
coinOp: CoinOp;
instructions: null | string;
serialized: null | string;
}
export interface CoinOpType {
message: string;
payload: Payload;
}Example CoinOp Object (Finalized State):
CoinOpId will always be CoinOp.payload.coinOp.id.
CoinOp.payload.coinOp.id.Game Provider Context:
Access the CoinOp methods:
All CoinOp games follow the same pattern:
Initialize
initCoinOp()Initialize the CoinOP
Send the serialized transaction. (Deposit)
Returns a CoinOp Object
Process
processCoinOp()Process & Retrieve the result of the CoinOp
Returns a CoinOp object.
Finalize
finalizeCoinOp()Check the win state of CoinOp
Process & Finalize CoinOp
Send claim transaction (If Won)
Returns a CoinOp object.
initCoinOp(amount: number, choice: string, auth: Authorization)
initCoinOp(amount: number, choice: string, auth: Authorization)This function is used to initialize a coin operation with a specified amount, choice, and authorization.
processCoinOp(coinOpId: string, auth: Authorization)
processCoinOp(coinOpId: string, auth: Authorization)This function is used to process a coin operation with a specified coin operation ID and authorization.
getCoinOp(auth: Authorization)
getCoinOp(auth: Authorization)This function is used to get a coin operation with a specified authorization.
Auth is part of the authorization context. (See the below example).
CoinOp also provides a currentCoinOp which has the object of the current CoinOp game, this can be used with the coinOp Methods, alternatively, you can choose to handle this state yourself.
Authorization:
CoinOpReact provides authorization methods, all users must have first connected their wallet using the Solana Wallet Adapter. CoinOp has a built-in wallet object which can be used with the signIn method.
Users must be authenticated before using any coinOp functions.
signIn
The signIn function is used to authenticate a user. It takes two parameters:
wallet: This is the user's wallet object.refferal: This is used to link a user's wallet to a referrer.
Here's an example of how to use it:
signOut
The signOut function is used to log out an authenticated user. It doesn't take any parameters.
Here's an example of how to use it:
Auth idToken:
When authenticating a coinOp method use idToken found under the auth object.
Remember to replace wallet and referral with the actual user's wallet (object, not public key) and refferal when using signIn.
Last updated