Skip to content

TESTNET — no value · TRON Nile

test TRX(opens in a new tab)
YourToken

Developers

YTK API

Read YourToken data over HTTPS and get a signed webhook when YTK arrives at an address you watch. The same data as this site, indexed from the TRON blockchain.

Start here

Quick start

Public data needs no sign-up. Every answer is JSON. The base URL of every endpoint below is:

https://tokenwallet.187.52.122.232.nip.io/v1
curl "https://tokenwallet.187.52.122.232.nip.io/v1/token"

Authentication

API keys and limits

Without a key you can make up to 60 requests a minute from one IP address. For more, and for webhooks, send an API key in the X-API-Key header:

With an API key
curl "https://tokenwallet.187.52.122.232.nip.io/v1/transfers?limit=100" \
  -H "X-API-Key: $API_KEY"
  • Keys are issued by the operator of this site from the admin panel. A key starts with ytk_ and is shown only once, when it is created.
  • Each key has its own limit: 600 requests a minute unless the operator set another number.
  • Over a limit, the API answers 429 Too Many Requests. Wait the number of seconds in the Retry-After header, then try again.
  • Keep keys on your server. Never put one in a web page or a mobile app. A revoked key stops working at once, and so do its webhooks.

Conventions

Amounts, pages and errors

Token amounts
Strings in base units, so nothing is lost to rounding. YTK has 6 decimals: "1500000" is 1.5 YTK.
TRX amounts
Strings in sun. 1 TRX is 1,000,000 sun.
Addresses
TRON addresses in base58, starting with T.
Times
ISO 8601, in UTC.
Status
pending broadcast, not in a block yet · confirmed in a block, after about 3 seconds · final solidified and irreversible, after about a minute · failed executed with an error.

Lists return items and nextCursor. To get the next page, pass nextCursor as cursor; it is null on the last page. limit is 1 to 100 and defaults to 25.

Paging
curl "https://tokenwallet.187.52.122.232.nip.io/v1/transfers?limit=100"
# {"items": [...], "nextCursor": "<cursor>"}
curl "https://tokenwallet.187.52.122.232.nip.io/v1/transfers?limit=100&cursor=<cursor>"

Errors come with an HTTP status code and a JSON body:

Error
{
  "statusCode": 404,
  "error": "Not Found",
  "message": "Transaction not found"
}
400
A parameter is missing or not valid. The message says which.
401
The API key is missing, wrong or revoked (webhook endpoints).
404
Nothing with this id or address.
409
Not possible right now, for example a faucet claim before the waiting time is over.
429
Too many requests. See Retry-After.
503
Temporarily unavailable. Try again shortly.

Reference

Endpoints

All paths start with /v1. Parameters, every field and live calls are in the interactive reference.

Token and explorer

Public
  • GET/token

    The token: supply, maximum supply, owner, number of holders and transfers.

  • GET/transfers

    All token transfers, newest first.

  • GET/holders

    Holders ranked by balance, with each share of the supply and the total count.

  • GET/addresses/{address}

    TRX and token balance of an address, and whether it is activated.

  • GET/addresses/{address}/transfers

    Token transfers of an address. direction=all, in or out.

  • GET/addresses/{address}/trx-transfers

    TRX transfers of an address.

  • GET/tx/{txId}

    One transaction: status, fee in energy and bandwidth, token transfers inside it.

  • GET/search?q={term}

    Tells whether a term is a transaction, an address or the token.

  • GET/health

    Indexer status: the last block read and how far behind the chain it is.

Testnet faucet

Testnet only
  • GET/faucet

    Amount per claim, waiting time and what is left in the faucet.

  • POST/faucet/claim

    Sends test tokens to {"address": "T…"}. Answers 409 while the address must wait.

Webhooks

API key
  • POST/webhooks

    Creates a webhook. The answer holds its signing secret, shown only this once.

  • GET/webhooks

    Your webhooks.

  • GET/webhooks/{id}

    One webhook.

  • PATCH/webhooks/{id}

    Changes the URL, addresses or events, or pauses it with "active": false.

  • DELETE/webhooks/{id}

    Deletes a webhook. Queued deliveries are dropped.

  • GET/webhooks/{id}/deliveries

    Delivery log: status, attempts, last HTTP status and error.

Push

Webhooks for incoming transfers

A webhook sends a POST request to your server when YTK arrives at an address you watch. One webhook watches up to 100 addresses; an API key can have up to 20 webhooks. There are two events:

transfer.confirmed
The transfer is in a block, a few seconds after it was sent.
transfer.final
The block is solidified and can no longer be reversed, about a minute later. Credit a customer only on this event.
Create a webhook
curl -X POST "https://tokenwallet.187.52.122.232.nip.io/v1/webhooks" \
  -H "X-API-Key: $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-server.example/hooks/ytk",
    "addresses": ["<the TRON address to watch>"],
    "events": ["transfer.final"]
  }'

The answer contains secret, starting with whsec_. It is shown only this once: store it, you need it to check that a request really comes from this site.

Each delivery is a POST with a JSON body and these headers:

X-Webhook-Event
transfer.confirmed or transfer.final
X-Webhook-Delivery
The delivery id, the same as id in the body
X-Webhook-Signature
t=<unix seconds>,v1=<HMAC-SHA256, hex>
User-Agent
YourToken-Webhooks/1.0
Body
{
  "id": "<delivery id, the same on every retry>",
  "type": "transfer.final",
  "createdAt": "<ISO 8601 time, UTC>",
  "network": "nile",
  "token": {
    "contractAddress": "<the YTK contract>",
    "symbol": "YTK",
    "decimals": 6
  },
  "data": {
    "txId": "<transaction id>",
    "eventIndex": 0,
    "blockNumber": 0,
    "timestamp": "<block time, UTC>",
    "from": "<sender>",
    "to": "<your watched address>",
    "amount": "<base units, as a string>",
    "status": "final"
  }
}
  • Answer with any 2xx status within 10 seconds. Otherwise the delivery is retried after 30 s, 2 min, 10 min, 30 min, 1 h, 3 h, 6 h and 12 h, then marked failed. Redirects are not followed.
  • A delivery can arrive more than once, for example when your server timed out after handling it. Its id never changes, so skip ids you have already handled.
  • The URL must use https and point to a public address.
  • GET /v1/webhooks/{id}/deliveries shows every attempt with the last HTTP status and error.

Security

Check a webhook signature

Before you trust a delivery, check its signature:

  1. Take t and v1 from the X-Webhook-Signature header.
  2. Compute the HMAC-SHA256 of {t}.{raw body} with your secret, in hex.
  3. Compare it with v1 in constant time.
  4. Reject the request if t is more than 5 minutes away from now.
import crypto from 'node:crypto';
import express from 'express';

const app = express();
const secret = process.env.WEBHOOK_SECRET; // whsec_…

// The signature covers the exact bytes sent, so read the raw body.
app.post('/hooks/ytk', express.raw({ type: 'application/json' }), (req, res) => {
  const body = req.body.toString('utf8');
  if (!verify(secret, req.get('x-webhook-signature'), body)) {
    return res.status(400).send('Bad signature');
  }
  const event = JSON.parse(body);
  // event.type is "transfer.confirmed" or "transfer.final"; event.data.amount is in base units
  res.sendStatus(200);
});

function verify(secret, header, body) {
  if (!header) return false;
  const parts = Object.fromEntries(header.split(',').map((part) => part.trim().split('=')));
  const timestamp = Number(parts.t);
  if (!Number.isInteger(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > 300) return false;
  const expected = crypto.createHmac('sha256', secret).update(`${timestamp}.${body}`).digest();
  const given = Buffer.from(parts.v1 ?? '', 'hex');
  return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}

app.listen(8080);