๐Ÿ–ฅ๏ธPortal APIs

Are you ready to take your Portal to the next level? ๐Ÿš€

Through integrating with the Sunflower Land API you will be able to access player data, burn and mint items!

Setup & Authorisation

Inside of your .env point your API to the dev server.

VITE_API_URL=https://api-dev.sunflower-land.com

When you run your application, you will need a custom JWT (authorisation token) that gives your portal users access to load game data and persist. For security, this JWT can only be created from the Sunflower Land Game.

Players who access your portal will provide this jwt to you through the url parameters. For instance:

crop-boom.sunflower-land.com/?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

You can then use this jwt to make calls to load player data and other useful APIs.

If you are testing locally, you can quickly attain a jwt by calling the authorisePortal()inside of portalUtils.ts

Load Player Data

<BASE_API_URL>/portal/<PORTAL_ID>/player

To load a player's data, you can use the endpoint above where PORTAL_ID is your portal name.

See the example below in loadPortal.ts

```typescript
import { makeGame } from "features/game/lib/transforms";
import { GameState } from "features/game/types/game";
import { CONFIG } from "lib/config";
import { ERRORS } from "lib/errors";

type Request = {
  portalId: string;
  token: string;
};

const API_URL = CONFIG.API_URL;

export async function loadPortal(request: Request) {
  // Uses same autosave event driven endpoint
  const response = await window.fetch(
    `${API_URL}/portal/${request.portalId}/player`,
    {
      method: "GET",
      headers: {
        "content-type": "application/json;charset=UTF-8",
        Authorization: `Bearer ${request.token}`,
      },
    }
  );

  if (response.status >= 400) {
    throw new Error(ERRORS.PORTAL_LOGIN_ERROR);
  }

  const data: { farm: GameState } = await response.json();

  const game = makeGame(data.farm);

  return { game };
}

```

Mint Arcade Token

<BASE_API_URL>/portal/<PORTAL_ID>/mint

Are you looking to reward your players with an Arcade Token? These can be minted once players have completed a challenge inside of your Portal. For instance, in Crop Boom once players have finished the puzzle and reached the other side.

You must first ask approval for your Portal to mint from the core team. Each Portal will have a Daily Allowance of Arcade tokens it can reward players.

Example in claimArcadeToken.ts

import { makeGame } from "features/game/lib/transforms";
import { GameState } from "features/game/types/game";
import { CONFIG } from "lib/config";
import { ERRORS } from "lib/errors";

type Request = {
  token: string;
};

const API_URL = CONFIG.API_URL;

export async function claimArcadeToken(request: Request) {
  // Uses same autosave event driven endpoint
  const response = await window.fetch(
    `${API_URL}/portal/${CONFIG.PORTAL_APP}/mint`,
    {
      method: "POST",
      headers: {
        "content-type": "application/json;charset=UTF-8",
        Authorization: `Bearer ${request.token}`,
      },
      body: JSON.stringify({
        items: {
          "Arcade Token": 1,
        },
      }),
    }
  );

  if (response.status >= 400) {
    throw new Error(ERRORS.PORTAL_LOGIN_ERROR);
  }

  const data: { game: GameState } = await response.json();

  const game = makeGame(data.game);

  return { game };
}  

Block Bucks

This endpoint will be used to use player's Block Bucks - monetise ๐Ÿค‘

Coming soon...

Mint Collectible or Wearable

Do you have a custom collectible or wearable you would like to reward players with? The team would love to hear your use cases

Coming soon...

Burn SFL/Resources

Coming soon...

Last updated