TRON

📘

/jsonrpc, /wallet, /walletsolidty support

Chainstack supports all three method endpoints:

  • /jsonrpc
  • /wallet
  • /walletsoldity

Note that the TRON nodes provided are full only (non-archive), which makes some of the methods unsupported.

For the full API reference, see the official TRON API Reference.

MetaMask

On node access details, click Add to MetaMask.

web3.py

Build DApps using web3.py and TRON nodes deployed with Chainstack.

  1. Install web3.py.
  2. Connect over HTTP. See also EVM node connection: HTTP vs WebSocket.

HTTP

Use the HTTPProvider to connect to your node endpoint and get the latest block number.

from web3 import Web3

web3 = Web3(Web3.HTTPProvider('YOUR_CHAINSTACK_ENDPOINT'))
print(web3.eth.block_number)
from web3 import Web3

web3 = Web3(Web3.HTTPProvider('https://%s:%s@%s'% ("USERNAME", "PASSWORD", "HOSTNAME")))
print(web3.eth.blockNumber)

where

  • YOUR_CHAINSTACK_ENDPOINT — your node HTTPS endpoint protected either with the key or password

See also node access details.

TronWeb.js

See TronWeb.

Here's an example of checking the TRX balance of a Binance cold wallet:

const TronWeb = require('tronweb');

// The base endpoint looks like https://tron-mainnet.core.chainstack.com/11111111222222222333333333444444
const chainstackUrl = 'CHAINSTACK_BASE_ENDPOINT';

const tronWeb = new TronWeb({
    fullHost: chainstackUrl
});

// The TRON address to check
const address = 'TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb';

async function checkBalance() {
    try {
        console.log(`Checking balance for address: ${address}`);
        
        // Append the base endpoint according to the call will make
        // See https://developers.tron.network/reference/
        const url = `${chainstackUrl}/wallet/getaccount`;
        
        const response = await tronWeb.fullNode.request(url, {
            address: tronWeb.address.toHex(address)
        }, 'post');
        
        // Output the raw response
        console.log('Raw response:');
        console.log(JSON.stringify(response, null, 2));
    } catch (error) {
        console.error('Error checking balance:', error.message);
        if (error.response) {
            console.error('Response status:', error.response.status);
            console.error('Response data:', JSON.stringify(error.response.data, null, 2));
        }
    }
}

checkBalance(); 

Notes:

  • CHAINSTACK_BASE_ENDPOINT — an endpoint that looks like https://tron-mainnet.core.chainstack.com/11111111222222222333333333444444, i.e. skipping the jsonrpc, wallet, walletsolidity appends.
  • Based on the call you are going to make, use the respective append. For example here, we are using GetAccount .
  • This example outputs raw response.
  • TronWeb does not have wrappers for all calls. You can check the TronWeb repository for the available wrappers. For example, as of April 2025, the GetAccountBalance call is not directly available.

Example of doing the GetAccountBalance call without the TronWeb library since it does not support the call:

const axios = require('axios');

// The base endpoint looks like https://tron-mainnet.core.chainstack.com/11111111222222222333333333444444
const chainstackUrl = 'CHAINSTACK_BASE_ENDPOINT';

// The TRON address to check
const address = 'TWd4WrZ9wn84f5x1hZhL4DHvk738ns5jwb';

// Function to convert Base58 address to hex format
function base58ToHex(base58Address) {
  const TronWeb = require('tronweb');
  return TronWeb.address.toHex(base58Address);
}

async function checkBalance() {
  try {
    // First, get the latest block because getaccountbalance call requires the block hash and number
    // See https://developers.tron.network/reference/getaccountbalance
    const blockUrl = `${chainstackUrl}/wallet/getnowblock`;
    const blockResponse = await axios.post(blockUrl);
    const blockNumber = blockResponse.data.block_header.raw_data.number;
    const blockHash = blockResponse.data.blockID;
    
    // Convert address to hex format
    const hexAddress = base58ToHex(address);
    
    // Make request to the getaccountbalance endpoint
    const url = `${chainstackUrl}/wallet/getaccountbalance`;
    const response = await axios.post(url, {
      account_identifier: {
        address: hexAddress
      },
      block_identifier: {
        number: blockNumber,
        hash: blockHash
      }
    });
    
    // Output the raw response
    console.log(JSON.stringify(response.data, null, 2));
  } catch (error) {
    if (error.response) {
      console.error(JSON.stringify(error.response.data, null, 2));
    } else {
      console.error(error.message);
    }
  }
}

checkBalance(); 

Hardhat

Configure Hardhat to deploy contracts and interact through your Klaytn nodes.

  1. Install Hardhat and create a project.

  2. Create a new environment in hardhat.config.js:

    require("@nomiclabs/hardhat-waffle");
    ...
    module.exports = {
      solidity: "0.7.3",
      networks: {
        chainstack: {
            url: "YOUR_CHAINSTACK_ENDPOINT",
            accounts: ["YOUR_PRIVATE_KEY"]
        },
      }
    };
    

    where

    • YOUR_CHAINSTACK_ENDPOINT — your node HTTPS or WSS endpoint protected either with the key or password. See node access details.
    • YOUR_PRIVATE_KEY — the private key of the account that you use to deploy the contract
  3. Run npx hardhat run scripts/deploy.js --network chainstack and Hardhat will deploy using Chainstack.

See also Forking EVM-compatible mainnet with Hardhat.

Remix IDE

To make Remix IDE interact with the network through a Chainstack node:

  1. Get MetaMask and set it to interact through a Chainstack node. See Interacting through MetaMask.
  2. In Remix IDE, navigate to the Deploy tab. Select Injected Provider - MetaMask in Environment.

This will engage MetaMask and make Remix IDE interact with the network through a Chainstack node.

Foundry

  1. Install Foundry.
  2. Use --rpc-url to run the operation through your Chainstack node.

Forge

Use forge to develop, test, and deploy your smart contracts.

To deploy a contract:

forge create CONTRACT_NAME --contracts CONTRACT_PATH --private-key YOUR_PRIVATE_KEY --rpc-url YOUR_CHAINSTACK_ENDPOINT

where

  • CONTRACT_NAME — name of the contract in the Solidity source code
  • CONTRACT_PATH — path to your smart contract
  • YOUR_PRIVATE_KEY — the private key to your funded account that you will use to deploy the contract
  • YOUR_CHAINSTACK_ENDPOINT — your node HTTPS endpoint protected either with the key or password

Cast

Use cast to interact with the network and the deployed contracts.

To get the latest block number:

cast block-number --rpc-url YOUR_CHAINSTACK_ENDPOINT

where YOUR_CHAINSTACK_ENDPOINT is your node HTTPS endpoint protected either with the key or password