跳转到内容

Authentication

此内容尚不支持你的语言。

The TEM API supports several authentication methods depending on the type of operation:

Method Description Used for
signed_tx A signed payment transaction that has not been broadcasted to the blockchain. Buys and deposits
signed_ms A signed message proving ownership of the address. Credit-based operations
api_key An API key that replaces the need to provide a signed message for every request. Credit-based operations

Credit is a prepaid balance. Instead of making an on-chain payment for each request, you can deposit funds into your account and use your available credit for supported operations.

Credit is the recommended way to use TEM as it can save a lot in fees and resources instead of making blockchain transactions each time you need to buy

Credit-based requests can be authenticated using either a signed message (signed_ms) or an API key (api_key).

An API key is just a 64-character hex string that identifies your address account. You can use an API key in order to avoid having to sign a message.

In order to generate an API key you need to:

  1. Go to Tron Energy Market and go to the top right.

  2. Open the 3 horizontal bar icon.

  3. Go to Manage api key

In case of loss you can regenerate it or you can request that we do it.

A signed transaction contains the transaction data plus a cryptographic signature proving that the wallet authorized it. It can usually be broadcast to the blockchain.

An example of a signed_tx would be:

const SERVER_ADDRESS = process.env.SERVER_ADDRESS
const ORIGIN = tronWeb.defaultAddress.base58; //sender of the TRX to add the credit.
const AMOUNT = 10000000; //amount of TRX to load as credit in sun
const raw_tx = await tronWeb.transactionBuilder.sendTrx(SERVER_ADDRESS, AMOUNT , ORIGIN);
const signed_tx = await tronWeb.trx.sign( raw_tx )

Signed message or signed payload (depends on the specific API/protocol). It proves that a particular wallet/account signed some data, but it is not necessarily a blockchain transaction.

Example of signed_ms:

const message = (new Date()).getTime().toString();
const signed_ms =
{
message: message,
signature: await tronWeb.trx.signMessageV2(tronWeb.toHex(message)),
version: 2
};