Get Token Balance

Allows users to fetch current token price in TRX and USD for a specific token (un-bonded) on SunPump.

Endpoint

  • URL: /sunpump/getTokenBalance

  • Method: GET

  • Content-Type: application/json

  • API Key Header: api-key: your-api-key

Parameters

ParameterTypeRequiredDescription

publicKey

string

Yes

Sender Public Tron Address

tokenAddress

string

Yes

Token Contract Address

tokenDecimals

number

No

The number of decimals used by the token. Defaults to 18

rpc

string

No

Optional custom Tron RPC URL

Example Request

curl -X POST https://api.dangeracorn.com/sunpump/getTokenBalance \
-H "Content-Type: application/json" \
-H "api-key: your-api-key" \
-d '{
  "publicKey": "sender-public-tron-address",
  "tokenAddress": "token-contract-address",
  "tokenDecimals": 18
}'

Example Response JSON

{
    "data": [{
    "priceInTRX": 0.0025,
    "priceInUSD": 0.0003735,
}], 
    "status": "success",
    "code": "200"
}

Error Responses

Invalid Public Key

{
  "error": "Invalid publicKey",
  "message": "Please check that the publicKey is a valid Tron address.",
  "status": "error",
  "code": "400"
}

Invalid Token Address

{
  "error": "Invalid tokenAddress",
  "message": "Please check that the tokenAddress is a valid Tron address.",
  "status": "error",
  "code": "400"
}

Balance Retrieval Error

{
  "error": "Error retrieving token balance",
  "message": "Failed to retrieve token balance. Please check your input values and try again.",
  "status": "error",
  "code": "500"
}

Notes

  • Balance Format: The API returns the balance in Sun (balanceInSun), and a human-readable format (convertedBalance) based on the provided decimals.

  • Rate Limiting: This endpoint is rate-limited according to your plan's API key limits. Ensure that you handle these limits in your application.

Last updated