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:
1
zombieFarm.methods.lastSessionId().call()
Copied!
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:
1
zombieFarm.methods.sessions(sessionId).call()
Copied!
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
https://api.seascape.network
/zombie-farm/get-level-options/:session_id/:level_id/:wallet_address
Get Level Options for the player
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.
seascape-smartcontracts/abi at game-5 · blocklords/seascape-smartcontracts
GitHub
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:
1
// for each challenge returned from the backend
2
for (var i=0; i<3; i++) {
3
let optionId = backendResponse[i].optionId;
4
5
// Get from the Zombie Farm contract
6
let challengeAddress = "";
7
8
// Get from game by backendResponse[i].category
9
let challengeAbi = "";
10
11
cc.challenges[optionId] = new web3.Contract(challengeAddress, challengeAbi);
12
}
Copied!

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:
1
let stake = backendResponse[i].singleTokenParams.stakeToken.address;
2
let abi = cc.blockchainConfig.crowns_abi
3
4
cc.stakes[optionId] = new web3.Contract(stake, abi);
Copied!

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
https://api.seascape.network/zombie-farm/get-level-options/:sesionid/:level_id/:wallet_address
api.seascape.network

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 speedUpmethod: 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:
1
let approveAmount = web3.utils.toWei("1000000", "ether");
2
window.stakes[challengeId].methods.approve(ZombieFarm._address, approveAmount ).send();
Copied!
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 claimmethod:
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 modified 5mo ago