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):
{
"message": "WAGMI",
"payload": {
"coinOp": {
"choice": "H",
"winAmounts": [
0.1
],
"status": "FINALIZED",
"numRounds": 1,
"createdAt": "2023-11-02T14:05:55.030Z",
"depositTxn": "2dmMp7LxwLnqSfgXDqEJRkHabW7KkCmdPZohD2jomUqbqPgUoW8FcY5X7RRP1TSk3Fh9avAbhgvPeMsLUbKsFE3p",
"walletId": "ted1iuDa4U4pwAxwVuvjbLxJMMPKruqtXkP53sHfqY6",
"gameSlug": "DCF",
"winAmount": 0.1,
"bonusRounds": 0,
"rolledItems": [
{
"mode": "NORMAL",
"itemId": "H",
"round": 1,
"probability": 0.5,
"rewards": [
{
"type": "BASE_MULTIPLIER",
"amount": 2
}
]
}
],
"won": true,
"gameMode": "NORMAL",
"amount": 0.05,
"resultTxn": "gspkzxgejBMtbVNYNCDGaczNSnWtgQm6FAeM22JZS27PNQQsX23JKRcGMBtmq3i2XxUHQVn5agpgMsYkN1KdNCG",
"id": "xsnm6uycz2x0veloaefru5ms",
"gameId": "cfYKc7m4e7Bb5cEo8FcDVDExeGWbFsrFehQpRUM7QWs"
},
"serialized": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAGDA07KMt+Hw6NVzYvtHY45SBHcmGI6NLgO46b0sSuVyR7/4Fe+a3oHKHdtsDMdEfqn87Um4CsWmdXgnaPT5YgqZaEmGCpuhIEQf2d4EV4hsVItdKmUwTFvCHLHm6cDKNcZQki59iq27QMMcYtub5F+j13JwEc0DlnoxO3qRqeB12QyKz0+Gz1sT8s3OZrILdj0fW8SHNcpazIiPeXGBJQX3jbzEA0IvAsBFBvsBXOuaqGAi9arDmUSa+VdbwkMZ2cDAVKU1qZKSEGTSTocWDaOHx8NbXdvJK7geQfqEBBBUSNAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAVNjeRqbJZYkLZB/6pcf06u7frv/u7xWC7rGVtetEJChULWf/JdsO/FvXaNArp7Jp6itrFJ8EGYKUlASfcwfyJBtLiSU/ZvOyGWUB8CSkKvXeBMdUVPDWq1yTYp6fpnusAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEG3Q1vSkAKqxdhUz7AHpuvXIVQThddymEf+jsb8opnVAwYBAFhpZD14c25tNnV5Y3oyeDB2ZWxvYWVmcnU1bXMgYW1vdW50PTAuMDUgZ2FtZT1jZllLYzdtNGU3QmI1Y0VvOEZjRFZERXhlR1diRnNyRmVoUXBSVU03UVdzBwAJA+gDAAAAAAAACAkACQoBAgMEBQsICSM7vqf5THMA",
"instructions": null
}
}
CoinOpId will always be CoinOp.payload.coinOp.id
.
CoinOp.payload.coinOp.id
.Game Provider Context:
Access the CoinOp methods:
import {useContext} from "react";
...
const CoinOp = useContext(CoinOpContext);
// coinOp.initCoinOp()
// coinOp.processCoinOP()
// etc...
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.
import { Authorizaion, AuthorizationContext } from "coinopreact/auth.context";
const { signIn, signOut, auth } = useContext(AuthorizationContext);
...
<button onClick={() => signIn(CoinOp.wallet, "")}>Sign In</button>
<button onClick={() => signOut()}>Sign Out</button>
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:
const { signIn } = useContext(AuthorizationContext);
signIn(wallet: WalletContextState, referral: string);
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:
const { signOut } = useContext(AuthorizationContext);
signOut();
Auth idToken:
When authenticating a coinOp method use idToken found under the auth object.
const {auth} = useContext(AuthorizationContext);
// auth.idtoken
Remember to replace wallet
and referral
with the actual user's wallet (object, not public key) and refferal when using signIn
.
Last updated