Token generation

Note: To utilize this endpoint, it is mandatory for the partner to have their AppID whitelisted by the Onramp team. Please contact the Onramp team to get your AppID whitelisted and gain access to this functionality.

This API endpoint allows you to generate a token for initiating the sell transaction of a specified quantity of cryptocurrency. The token can be used for further interactions with the sell order endpoint.

POST api.onramp.money/onramp/api/v2/sell/transaction/generateToken

Request Body

NameTypeDescription

messsageToSign*

String

The message to be signed by the Partner/wallet holder

appId

String

appId -> App Id of the merchant/Partner.

quantity*

String

quantity of cryptocurrency that is expected to be received

walletAddress*

String

Onchain wallet address to which the crypto was withdrawn to

signedMessage*

String

The signed message generated by the Partner/wallet holder

chainId*

String

chainId -> denotes which chain the coin was sent on (e.g. 3

denotes MATIC20)

coinId*

String

coinId -> Id of the coin (e.g. 54 denotes to USDT)

{
  "status": 1,
  "code": 200,
  "data": {
    "token": "eyJhbGc...iOiJIUzI",
    "depositAddress": "0x1f5b...df43"
  }
}

note: recommended web3 version - 1.8.1

npm install web3@1.8 axios crypto-js
var CryptoJS = require('crypto-js');
const axios = require('axios');
const Web3 = require("web3");
const web3 = new Web3();

let apiKey = 'API_KEY'
let apiSecret = 'API_SECRET'

async function generateToken() {
  try {

    let walletAddress = '0xf1421..c0db37f';
    let timestamp = Date.now();
    const messageToSign = `This is my address ${walletAddress}. I am signing it at ${timestamp}`;
    let walletPrivateKey = "WALLET_PRIVATE_KEY";
    let signedMessage = web3.eth.accounts.sign(messageToSign, "0x" + walletPrivateKey);
    signedMessage = signedMessage.signature;
    let body = {
      messageToSign,
      signedMessage,
      walletAddress,
      quantity: 100,
      coinId: 54,
      chainId: 3
    };

    let requestBody = { timestamp, body };

    let payload = Buffer.from(JSON.stringify(requestBody)).toString('base64');
    const signature = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA512(payload, apiSecret));

    let options = {
      url: "http://api.onramp.money/onramp/api/v2/sell/transaction/generateToken",
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json;charset=UTF-8',
        'X-ONRAMP-SIGNATURE': signature,
        'X-ONRAMP-APIKEY': apiKey,
        'X-ONRAMP-PAYLOAD': payload
      },
      data: JSON.stringify(body)
    };

    const response = await axios(options);

    if (response.data.status === 1) {
      console.log('Token:', response.data.data.token);
      console.log('Deposit Address:', response.data.data.depositAddress);
      console.log()
    } else {
      console.error('Error:', response.data.error);
    }
  } catch (error) {
    console.error('Error:', error?.response?.data);
  }
}

generateToken();

{
  "status": 1,
  "code": 200,
  "data": {
    "token": "eyJhbGc...iOiJIUzI",
    "depositAddress": "0x1f5b...df43"
  }
}

Last updated