crazydice-sdk
v1.0.5
Published
## Intro
Readme
CrazyDice Gaming SDK
Intro
CrazyDice Gaming SDK is toolkit provided by Crazy Dice Metaverse.
Install
npm install crazydice-sdkUsage
中文使用文档
错误处理:
code码目前仅0和400,0代表正常,400代表错误,错误信息会通过message返回- Step 1: 安装并导入SDK
- Step 2: 登录,确保用户已经连接钱包并选择网络,可以通过
getAccount获取账户信息,如果isConnected == true则已连接,否则需要调用openLogin让用户连接钱包 - Step 3: 选择角色,调用
getGameCharacter会弹出窗口让用户选择角色,用户选择角色后会返回角色信息,否则返回code==400需要重新让用户选择角色 - Step 4: 获取到角色信息后,将角色ID作为唯一标识绑定游戏数据,并且将角色的基础属性附加到游戏中,注意:百分比加成是最终百分比加成,固定加成是直接加在角色属性上
- Step 5: 广告需要调用
openAD,需要传参数:广告类型,目前仅支持reward(激励广告),会有用户操作相应返回值 - Step 6: 支付功能,调用
buyProduct,传入支付金额即可,会调起钱包支付,成功将会返回一个交易hash,代表付款成功
English Usage Document
Error Handling: The current code values are only
0and400.0represents normal operation, and400represents an error. Error messages will be returned viamessage.- Step 1: Install and import the SDK
- Step 2: Log in. Ensure the user has connected their wallet and selected a network. You can get account information via
getAccount. IfisConnected == true, the user is connected. Otherwise, you need to callopenLoginto prompt the user to connect their wallet. - Step 3: Select a character. Calling
getGameCharacterwill display a window for the user to select a character. If a character is selected, the character information will be returned; otherwise,code == 400will be returned, and the user will need to select a character again. - Step 4: After obtaining the character information, bind the game data using the character ID as a unique identifier and add the character’s basic attributes to the game. Note: Percentage bonuses are final percentage bonuses, while fixed bonuses are directly added to the character's attributes.
- Step 5: For advertisements, call
openADand pass in the parameter: ad type. Currently, only reward ads (incentive ads) are supported. There will be corresponding return values based on user actions. - Step 6: For the payment function, call
buyProductand pass in the payment amount. This will trigger wallet payment. A transaction hash will be returned upon successful payment, indicating the payment was successful.
Init
import { CrazyDiceSDKConfig, CrazyDiceSDK } from 'crazydice-sdk'
const config: CrazyDiceSDKConfig = {
appId: BigInt(1000000),
name: 'GameName',
logo: '',
gameLink: 'https://game.domain',
version: '1.0.0',
env: 'sandbox', // 'sandbox' | 'production'
}
const sdk = new CrazyDiceSDK(config)API
openLoginOpen the wallet connection
const resp = await sdk.openLogin() // ----------------------------------------------- // Refuse to buy Resp Example: // // { // "id": "452363267331981312_GetAccount", // "payload": { // "code": 400, // "msg": "reason", // } // }getAccountGet Account info
const resp = await sdk.getAccount() // No wallet connected Resp Example: // // { // "id": "452367020219039744_GetAccount", // "payload": { // "code": 0, // "msg": "ok", // "data": { // "isConnected": false, // "isConnecting": false, // "isDisconnected": true, // "isReconnecting": false, // "status": "disconnected" // } // } // } // ------------------------------------------------- // Connected wallet Resp Example: // // { // "id": "452363267331981312_GetAccount", // "payload": { // "code": 0, // "msg": "ok", // "data": { // "address": "0xd0f4C437bAb98404e911Cf5042800DCb157fb53f", // user wallet address // "addresses": [ // "0xd0f4C437bAb98404e911Cf5042800DCb157fb53f" // ], // "chain": { // "id": 57000, // "name": "Rollux Testnet", // "nativeCurrency": { // "decimals": 18, // "name": "Syscoin", // "symbol": "SYS" // }, // "rpcUrls": { // "default": { // "http": [ // "https://rpc-tanenbaum.rollux.com/" // ], // "webSocket": [ // "wss://rpc-tanenbaum.rollux.com/wss" // ] // } // }, // "blockExplorers": { // "default": { // "name": "RolluxTestnetExplorer", // "url": "https://rollux.tanenbaum.io", // "apiUrl": "https://rollux.tanenbaum.io/api" // } // }, // "contracts": { // "multicall3": { // "address": "0xcA11bde05977b3631167028862bE2a173976CA11", // "blockCreated": 1813675 // } // } // }, // "chainId": 57000, // "connector": { // "name": "MetaMask", // "id": "io.metamask", // "type": "injected", // "uid": "d1381ea8b19" // }, // "isConnected": true, // "isConnecting": false, // "isDisconnected": false, // "isReconnecting": true, // "status": "reconnecting" // } // } // }getBalanceGet Balance
const resp = await sdk.getBalance() // Get Balance Resp Example: // // { // "id": "452363267331981312_GetAccount", // "payload": { // "code": 0, // "msg": "ok", // "data": { // decimals: 18 // formatted: "1.022196946825351073" // symbol: "SYS" // value: 1022196946825351073n // } // } // }openADGet AD
const resp = await sdk.openAD('reward') // 'preroll' | 'start' | 'pause' | 'next' | 'browse' | 'reward' // Currently only supports rewarded adsopenCrazyDiceOpen Crazy Dice Window
const resp = await sdk.openCrazyDice("{charaterTokenId}") // Open CrazyDice windowbuyProductBuy Product Payment
const resp = await sdk.buyProduct('0.01') // Buy Success Resp Example: // // { // "id": "452363267331981312_GetAccount", // "payload": { // "code": 0, // "msg": "ok", // "data": { // hash: "0x....." // } // } // }getGameCharacterget game character info
const resp = await sdk.getGameCharacter() // Get Game Character Resp Example: // // { // "id": "456045418183262208_GetGameCharacter", // "payload": { // "code": 0, // "msg": "ok", // "data": { // "charcaterId": "57000_0x5401224da27a98133862f653b6ee804d61cf8596_1", // Unique ID for each character // "attrs": [ // Different slots have different attribute bonuses. Please refer to the slot attribute comparison table. // { // "slotId": "10003", // "isPercent": false, // "name": "HP HEAL", // "value": "7" // }, // { // "slotId": "10004", // "isPercent": true, // "name": "SPD", // "value": "1" // }, // { // "slotId": "10006", // "isPercent": true, // "name": "C.DMG", // "value": "1" // }, // { // "slotId": "100000", // "isPercent": true, // "name": "ATK", // "value": "0.01" // }, // { // "slotId": "10001", // "isPercent": false, // "name": "ATK", // "value": "10" // }, // { // "slotId": "10002", // "isPercent": false, // "name": "HP", // "value": "100" // } // ], // "slotToImage": { // Pictures showing different slot positions // "10": "1", // "20": "1", // "30": "1", // "40": "1", // "50": "1", // "60": "1" // } // } // } // }
Data comparison table
Slot Attributes
HeartOfTheBrave
| SlotId | Attribute | | ---------- | ------------- | | 100000 | HP HEAL | | 200000 | HP | | 300000 | SPD | | 400000 | ATK | | 500000 | C.DMG | | 600000 | CRIT | | 10001 | HP | | 10002 | HP HEAL | | 10003 | SPD | | 10004 | ATK | | 10005 | C.DMG | | 10006 | CRIT | | 10 | LeftLeg | | 20 | RightLeg | | 30 | LeftHand | | 40 | Body | | 50 | RightHand | | 60 | Head |
