API call order
The order of interaction with backend
Game Start
Here is the list in order of API to call when game is launched. This data is to be shown in the Levels page, not in the main menu.
1. Fetch Session Data (Smartcontract)
The Session data contains general information about how many levels the current season has, the grand reward type and so on. This API is containing two parts. First we get the latest Session ID:
It returns the session id for the current running season. Or for the latest closed season.
Once we have the session id, we can get the latest session data:
It returns the Session struct defined in the Game's smart contract.
For now, the Smart Contract is not ready, but we will put here the Struct, once the Smart Contract will be ready.
2. Fetch Level Parameters (Backend)
After fetching the Season (also called Session), we show the first level. Each level will have three staking options. The options are different for each player. So let's get the first level information from the API backend:
Get Level Options for the player
GET
https://api.seascape.network/zombie-farm/get-level-options/:session_id/:level_id/:wallet_address
Return the options to show for the user.
Path Parameters
Name | Type | Description |
---|---|---|
wallet_address | string | The Wallet address of the user. It should start with 0x prefix. |
level_id | integer | Level ID |
session_id | integer | Season ID |
For more information about structure of singleTokenParams, or to know more about the names and the structures of staking/earning parameters of another option category, please visit Option categories
3. Create instance of contracts for each Challenge.
Once we get the challenge data, we need to create the Contract Instance of them in our game. The contract instances are used later.
For creating the contract instance we need two parameters. The first is contract address. The second is ABI interface.
Getting the address
Call the backend method:
window.zombieFarm.methods.supportedChallenges(optionId).call()
The parameters of supportedChallenges are:
optionId - The challenge (aka option) id that we received from the backend, when we fetched level data.
Getting the ABI
Copy the ABI from the github repo in the game.
And assign each abi to option category. For example for "single-token" option category, use SingleTokenChallenge.json fetched from github.
Finally once we know how to get ABI and address of the option, we need to create Contract instances and assign to each challenge (aka option) id:
4. Create instances of staking tokens.
For each challenge, we need to create an instance of staking token. For Single Token category challenges, the staking token instance is created as like this:
Repick
In order to decide to show the "Repick" button on the challenge card or not visit the Challenge card page.
Here is the steps to reproduce the "Repick" button.
1. Open the popup about Repick fee.
The Repick fee is in Crowns, and is available at window.session.repickFee
. Since the repick fee is in Wei, we need to show to user in float format: web3.utils.fromWei(window.session.repickFee)
In Cocos Creator framework, the window.session
will be available as cc.session
.
2. Send transaction to Zombie Farm contract
Once the player gets confirmation about repick fee, he clicks on "send" button on popup. The click will send a transaction to the zombie farm contract by calling
window.zombieFarm.methods.repick(
sessionId
,
challengeId
).send()
The parameters passed to repick
method:
sessionId - The current game season.
challengeId - The current challenge that user wants to replace.
3. Return player option data from server.
Just like at Game Start, Fetch the level parameters
Boost
In order to decide to show the "Boost" button on the challenge card or not visit the Challenge card page.
Here is the steps to reproduce the "Repick" button.
1. Open the popup about Boost fee.
The Boost fee is in Crowns, and is available at window.session.speedUpFee
. Since the repick fee is in Wei, we need to show to user in float format: web3.utils.fromWei(window.session.speedUpFee)
In Cocos Creator framework, the window.session
will be available as cc.session
.
2. Send transaction to Zombie Farm contract
Once the player gets confirmation about repick fee, he clicks on "send" button on popup. The click will send a transaction to the zombie farm contract by calling
window.zombieFarm.methods.speedUp(
sessionId
,
challengeId
).send()
The parameters passed to speedUp
method:
sessionId - The current game season.
challengeId - The current challenge that user wants to speed up.
3. Update the Challenge card.
If transaction went successfully, update the card, including the timer to completed stage.
Stake
First we approve user's staking token to use his tokens in Zombie Farm.
We do it by calling:
The staking parameters that are sent to smart contract calls the method:
window.zombieFarm.methods.stake(
sessionId
,
challengeId
,
data
).send()
The arguments of stake
method:
sessionId - The current active game season.
challengeId - The challenge for which user wants to stake.
data - the byte parameter of the challenge about staking tokens. It is different for each option category. So please look at option categories page.
Unstake
The unstaking parameters that are sent to smart contract calls the method:
window.zombieFarm.methods.unstake(
sessionId
,
challengeId
,
data
).send()
The arguments of unstake
method:
sessionId - The current active game season.
challengeId - The challenge for which user wants to stake.
data - the byte parameter of the challenge about unstaking tokens. It is different for each option category. So please look at option categories page.
Claim
User claims the tokens that farmed by staking token. It is done by calling the method:
window.zombieFarm.methods.claim(
sessionId
,
challengeId
).send()
The arguments of claim
method:
sessionId - The current active game season.
challengeId - The challenge for which user wants to stake.
Once its check the value of logs for earned tokens.
Last updated