Tron - Getting Started (REST API)

This article covers the steps required to create a Tron wallet and generate addresses and private keys. It includes an example of checking the address balance and transferring funds to another Tron address.

πŸ“˜

The following steps and examples are based on Tron Shasta (Testnet).

Steps

Step_1: Generate a Mnemonic

Generating a mnemonic means creating a 24-word phrase that will be the foundation for your wallet. This phrase is like a master key from which all your wallet addresses and their private keys can be generated.

  • Tatum does not store Mnemonics and or Private Keys.
  • The responsibility of keeping your Mnemonics and Private Keys secure rests solely with you, the User.
  • Additional information about Mnemonics and Private Keys is available in the following article.

Example request:

  • The response returns a Mnemonic and a Tron XPUB
curl --location 'https://api.tatum.io/v3/tron/wallet' \
--header 'accept: application/json' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response

{
    "mnemonic": "asset charge scorpion attract leopard benefit brother sleep fresh dish again error silk debris need text legal pink add wreck #### #### #### ####",
    "xpub": "xpub6EpsqSH183RcDSHTSYkdhZcYX2Z99EhyJYvn8faqif968xyNoc9H3gu3Ewo66Pq5kJk4AURty6jggTB5HE5iC9Td2aJecAsTLsRkULBQZgd"
}

πŸ“˜

Be mindful of Tatum's Derivation Path.

Step_2: Generate a Tron Private Key from Mnemonic and index

Creating a private key is creating a unique and secret key that belongs to you. This key is crucial for accessing and controlling your funds.

Example request:

  • The response returns a Tron Private Key based on index 1.
curl --location 'https://api.tatum.io/v3/tron/wallet/priv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
    "mnemonic": "asset charge scorpion attract leopard benefit brother sleep fresh dish again error silk debris need text legal pink add wreck #### #### #### ####",
    "index": 1
}'
//Response:
{
    "key": "####"
}

Step_3: Generate a Tron address from XPUB and index

Generating an address is about creating a public address where others can send you funds. It's like an account number in the blockchain world.

Example request:

  • The response returns a Tron Address based on index 1
curl --location 'https://api.tatum.io/v3/tron/address/xpub6EpsqSH183RcDSHTSYkdhZcYX2Z99EhyJYvn8faqif968xyNoc9H3gu3Ewo66Pq5kJk4AURty6jggTB5HE5iC9Td2aJecAsTLsRkULBQZgd/1' \
--header 'accept: application/json' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "address": "TF48MUvZhSDpLFfC414b94Nj4LwqBFbXom"
}

Step_4: Add funds to the Tron address

We take the address generated in step_3. For testnet, you can get free coins from a faucet. Find additional information in the following article.

πŸ“˜

Adding TRX (TRON Native coin) to the address for the first time will activate it.

{
    "address": "TF48MUvZhSDpLFfC414b94Nj4LwqBFbXom"
}

Step_5: Check the balance of a Tron address

🚧

Newly created Tron addresses need to be activated before they can be found via API queries or on the chain explorer. Additional information in the following article.

Request example:

  • The response returns the balance from a Tron address
curl --location 'https://api.tatum.io/v3/tron/account/TF48MUvZhSDpLFfC414b94Nj4LwqBFbXom' \
--header 'accept: application/json' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "balance": 5000000000,
    "createTime": 1719225900000,
    "trc10": [],
    "trc20": [],
    "freeNetLimit": 600,
    "bandwidth": 600
}

Step_6: Consider the potential fees of a Tron transaction

Tron has a unique approach to its fees. Additional information is available in the following article.

Step_7: Sign and broadcast a Tron transaction

Request example:

  • The response returns a transaction hash
curl --location 'https://api.tatum.io/v3/tron/transaction' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '
{
  "fromPrivateKey": "SENDER_ADDRESS_PRIVATE_KEY",
  "to": "TJWCFsbeK6aybMTnsis1mccNX4gjW4ecah",
  "amount": "1000"
}
'
//Response:
{
    "txId": "cbafc7eccf7a45bccb8153e190e1d19136d11770055d3e63d3e41176b899b84b"
}

Step_8: Get the details of a Tron transaction

Request example:

  • The response returns the details of a Tron transaction hash
curl --location 'https://api.tatum.io/v3/tron/transaction/cbafc7eccf7a45bccb8153e190e1d19136d11770055d3e63d3e41176b899b84b' \
--header 'accept: application/json' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "ret": [
        {
            "contractRet": "SUCCESS"
        }
    ],
    "signature": [
        "571172a85f1d2269ded7f7ef08e26ac543b707d66fe3a9ced8a137269f4119697128ef704b32ada253e3d51d29c7ba9d29fc0051a0e2f0b24f21f79945be32661b"
    ],
    "blockNumber": 45223389,
    "txID": "cbafc7eccf7a45bccb8153e190e1d19136d11770055d3e63d3e41176b899b84b",
    "netUsage": 269,
    "rawData": {
        "contract": [
            {
                "parameter": {
                    "value": {
                        "amount": 1000000000,
                        "owner_address": "4137c6d4314d14dfdc8502e5487240dfb0eabd169d",
                        "to_address": "415d9d478fdf818f93c9c52c74da21f8a66a19b92d",
                        "ownerAddressBase58": "TF48MUvZhSDpLFfC414b94Nj4LwqBFbXom",
                        "toAddressBase58": "TJWCFsbeK6aybMTnsis1mccNX4gjW4ecah"
                    },
                    "type_url": "type.googleapis.com/protocol.TransferContract"
                },
                "type": "TransferContract"
            }
        ],
        "ref_block_bytes": "0ddb",
        "ref_block_hash": "0a8fbf9af093fcec",
        "expiration": 1719226821000,
        "timestamp": 1719226761000
    }
}

Good to Know