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

Documentation
Develop
Dapp
SelSwap
API
Token

Token

Mint

This API endpoint allows authenticated users to mint new tokens for their organization. (Only owner of organization can mint it)

It requires authentication using a valid access token (implement isAuthenticated middleware).

API ENDPOINTS

Request Body:

FieldTypeDescriptionRequired
api_keystringThe API key of the organization.Yes
merchant_idString (URL)The merchant ID of the organization.Yes
amountNumberThe number of tokens to be minted.Yes
receiver_addressStringThe Ethereum address of the recipient for the minted tokens.Yes

API example

const axios = require("axios");
let data = JSON.stringify({
  api_key: "ff73dc8c-8fba-48b3-b1b2-6482d5933729",
  merchant_id: "selendra",
  amount: "1000",
  receiver_address: "0x604b2f75d6ef9bd68A97Fb3C6c614fe8FE11bdfc",
});
 
let config = {
  method: "post",
  maxBodyLength: Infinity,
  url: "https://gateway.selendra.org/token/mint",
  headers: {
    Authorization: token,
    "Content-Type": "application/json",
  },
  data: data,
};
 
axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Response Example (Success):

{
  "status": "SUCCESS",
  "message": "token minted successfully"
}

Response Example (Error):

{
  "status": "ERROR",
  "message": "Invalid merchant_id or token_id"
}

Code Errors:

  • 400: Bad Request - Invalid request body or missing required fields.
  • 401: Unauthorized - Authentication failed (invalid or missing access token).
  • 404: Not Found - Organization or token data not found.

Swap

This API endpoint allows authenticated users to swap tokens between organizations.

It requires authentication using a valid access token (implement isAuthenticated middleware).

API ENDPOINTS

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

Request Header:

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

API example

const axios = require("axios");
let data = JSON.stringify({
  from_token: "1",
  to_token: "2",
  amount: "100",
});
 
let config = {
  method: "post",
  url: "https://gateway.selendra.org/token/swap",
  headers: {
    Authorization: token,
    "Content-Type": "application/json",
  },
  data: data,
};
 
axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Response Example (Success):

{
  "status": "SUCCESS",
  "message": "Swapped successfully"
}

Response Example (Error):

{
  "status": "ERROR",
  "message": "Invalid partner_token_id"
}

Code Errors:

  • 400: Bad Request - Invalid request body or missing required fields.
  • 401: Unauthorized - Authentication failed (invalid or missing access token).
  • 404: Not Found - Organization or token data not found.

Security Considerations:

  • This endpoint requires authentication to protect user accounts.
  • User PINs are used for authorization, highlighting the importance of strong PINs.

Additional Notes:

  • This endpoint interacts with a blockchain smart contract to perform the token swap between organizations.
  • The specific implementation for swapping tokens (e.g., getContract(user_private_key).swap(1, 2, 100)) might need to be adjusted based on your actual smart contract functions.

Transfer

This API endpoint allows authenticated users to transfer their organization's tokens to another wallet address.

It requires authentication using a valid access token (implement isAuthenticated middleware).

API ENDPOINTS

Request Body:

FieldTypeDescriptionRequired
wallet_addressStringThe Ethereum address of the recipient for the tokens.Yes
token_idNumberThe token ID of the organization's token to be transferred.Yes
amountNumberThe amount of tokens to be swapped.Yes

Request Header:

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

API example

const axios = require("axios");
let data = JSON.stringify({
  wallet_address: "0xAbCeDE5c2B35214ca7aFA98b29Ff937C737D5b2a",
  token_id: "1",
  amount: "10000",
});
 
let config = {
  method: "post",
  maxBodyLength: Infinity,
  url: "http://localhost:3000/token/transfer",
  headers: {
    Authorization: token,
    pin: "1111",
    "Content-Type": "application/json",
  },
  data: data,
};
 
axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Success Response:

{
  "status": "SUCCESS",
  "data": "Points transfer successfully."
}

Error Response:

{ "status": "ERROR", "message": "User not found" }

Code Errors:

  • 400: Bad Request - Invalid request body or missing required fields.
  • 401: Unauthorized - Authentication failed (invalid or missing access token).
  • 404: Not Found - User data not found.

Additional Notes:

  • This endpoint interacts with a blockchain smart contract to transfer tokens from the user's organization to the specified recipient address.
  • The amount is likely multiplied by 100 before the transfer to handle decimals (depending on your token implementation).

Balance

This API endpoint allows anyone to retrieve the balance of a specific token for a given wallet address.

API ENDPOINTS

Request Body:

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

API example

const axios = require("axios");
let data = JSON.stringify({
  token_id: "1",
  wallet_address: "0xAbCeDE5c2B35214ca7aFA98b29Ff937C737D5b2a",
});
 
let config = {
  method: "post",
  url: "https://gateway.selendra.org/token/balance",
  headers: {
    "Content-Type": "application/json",
  },
  data: data,
};
 
axios
  .request(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Success Response:

{
  "status": "SUCCESS",
  "data": {
    "wallet_address": "0x1234567890Abcdef1234567890Abcdef123456789",
    "balance": "100.00" // Balance formatted with 2 decimal places
  }
}

Error Response:

{
  "status": "ERROR",
  "message": "Error fetching token balance"
}

Notes:

  • This endpoint does not require authentication, making the token balance information publicly accessible.
  • The balance is formatted with 2 decimal places using ethers.formatUnits(balance, 2).