🌱 This is a live document. Continuous updates are forthcoming!

Documentation
Develop
Dapp
SelSwap
Frontend

Connect API to Frontend

This section shows how to connect to SelSwap API on Bitriel Reward app.

Run Example App

Step 1: Clone Project

  1. Open your terminal.
  2. git clone git@github.com:bitriel/bitriel-rewards.git

Step 2: Navigate into your project directory

  1. Run cd bitriel-rewards to navigate project directory.
  2. Run npm install to install dependencies

Step 3: Navigate into your project directory

  1. Init eas eas init
  2. Build development build eas build --profile development --platform android --local on android or eas build --profile development --platform android --local on ios
  3. After build, install file to physical or simulator/emulator device

Step 4: Start the development server

  1. Run npm run start to start the development server.

You will see the following app:

Screen 1Screen 2
Craete PINConfirm PIN

Integration Details

The app integrates with the following APIs:

1. Create User

  • URL: https://gateway.selendra.org/account/create (opens in a new tab)

  • Method: POST

  • Content-Type: 'application/json'

    Request Body:

    FieldTypeDescriptionRequired
    usernamestringThe desired username for the new account.Yes
    passwordstringThe password for the new account.Yes

    API example

    export const createWallet = async (
      username: string,
      password: string
    ) => {
      try {
        const response = await axios.post(
          `https://gateway.selendra.org/account/create`,
          {
            username: username,
            password: password,
          }
        );
     
        return response.data;
      } catch (error) {
        throw error;
      }
    };
  • Screenshot:

    Screen Register
    Register User

2. Create User PIN

  • URL: https://gateway.selendra.org/account/create/pin (opens in a new tab)

  • Method: POST

  • Content-Type: 'application/json'

    Request Body:

    FieldTypeDescriptionRequired
    usernamestringThe desired username for the new account.Yes
    pinstringThe desired PIN for the user account.Yes

    API example

    export const createPIN = async (
      username: string,
      pin: string,
      token: string
    ) => {
      try {
        const response = await axios.post(
          `https://gateway.selendra.org/account/create/pin`,
          {
            username: username,
            pin: pin,
          },
          {
            headers: {
              Authorization: token,
            },
          }
        );
     
        return response.data;
      } catch (error) {
        throw error;
      }
    };
  • Screenshot:

    Create PINConfirm Pin
    Craete PINConfirm PIN

3. Login

  • URL: https://gateway.selendra.org/account/login (opens in a new tab)

  • Method: POST

  • Content-Type: 'application/json'

    Request Body:

    FieldTypeDescriptionRequired
    usernamestringThe username of the user.Yes
    passwordstringThe password of the user.Yes

    API example

    export const loginWallet = async (username: string, password: string) => {
      try {
        const response = await axios.post(
          "https://gateway.selendra.org/account/login",
          {
            username: username,
            password: password,
          }
        );
     
        return response.data;
      } catch (error) {
        throw error;
      }
    };
  • Screenshot:

    Login
    Create PIN

4. Fetch Balance Point

  • URL: https://gateway.selendra.org/token/balance (opens in a new tab)

  • Method: POST

  • Content-Type: 'application/json'

    Request Body:

    FieldTypeDescriptionRequired
    token_idNumberThe token ID of the organization's token.Yes
    wallet_addressstringThe Ethereum address of the wallet to check the balance.Yes

    API example

    export const fetchBalance = async (
      tokenId: string,
      walletAddress: string
    ): Promise<BalanceType> => {
      try {
        const response = await axios.post(
          "https://gateway.selendra.org/token/balance",
          {
            token_id: tokenId,
            wallet_address: walletAddress,
          }
        );
     
        const balanceData: BalanceType = response.data["data"];
     
        return balanceData;
      } catch (error) {
        throw error;
      }
    };
  • Screenshot:

    HomeHome
    Create PINConfirm PIN

5. Swap Point

  • URL: https://gateway.selendra.org/token/swap (opens in a new tab)

  • Method: POST

  • Content-Type: 'application/json'

    Request Header:

    FieldDescriptionRequired
    pinThe user's PIN for authorization (swap from_token to to_token).Yes

    Request Body:

    FieldTypeDescriptionRequired
    from_tokenNumberThe token ID of the token being exchanged (from organization).Yes
    to_tokenNumberThe token ID of the desired token (to organization).Yes
    amountNumberThe amount of tokens to be swapped.Yes

    API example

    export const swapPoint = async (
      authToken: string,
      pin: string,
      fromToken: string,
      toToken: string,
      amount: string
    ) => {
      try {
        const response = await axios.post(
          "https://gateway.selendra.org/token/swap",
          {
            from_token: fromToken,
            to_token: toToken,
            amount: amount,
          },
          {
            headers: {
              Authorization: authToken,
              pin: pin,
            },
          }
        );
     
        return response.data;
      } catch (error) {
        throw error;
      }
    };
  • Screenshot:

    SwapConfirm Pin
    Create PINConfirm PIN

6. Transfer Point

  • URL: https://gateway.selendra.org/token/transfer (opens in a new tab)

  • Method: POST

  • Content-Type: 'application/json'

    Request Header:

    FieldDescriptionRequired
    pinThe user's PIN for authorization (swap from_token to to_token).Yes

    Request Body:

    FieldTypeDescriptionRequired
    usernamestringThe desired username for the new account.Yes
    passwordstringThe password for the new account.Yes

    API example

    export const transferToken = async (
      authToken: string,
      pin: string,
      walletAddress: string,
      tokenId: string,
      amount: string
    ) => {
      try {
        const response = await axios.post(
          "https://gateway.selendra.org/token/transfer",
          {
            wallet_address: walletAddress,
            token_id: tokenId,
            amount: amount,
          },
          {
            headers: {
              Authorization: authToken,
              pin: pin,
            },
          }
        );
     
        return response.data;
      } catch (error) {
        throw error;
      }
    };
  • Screenshot:

    Create PINConfirm Pin
    Create PINConfirm PIN