Skip to main content
Version: 6.2.2

Provider Configuration

TronWeb supports flexible node provider configuration for connecting to different TRON networks and custom nodes.

Basic Configuration

The simplest configuration — uses the same URL for all services:

import TronWeb from 'tronweb';

const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
headers: { 'TRON-PRO-API-KEY': 'your-api-key' },
privateKey: 'your-private-key',
});

Individual Node Configuration

Specify separate endpoints for each service:

const tronWeb = new TronWeb({
fullNode: 'https://api.trongrid.io',
solidityNode: 'https://api.trongrid.io',
eventServer: 'https://api.trongrid.io',
headers: { 'TRON-PRO-API-KEY': 'your-api-key' },
privateKey: 'your-private-key',
});

Network Endpoints

Mainnet

ProviderURL
TronGridhttps://api.trongrid.io
Custom nodeYour self-hosted Full Node URL

Nile Testnet

ProviderURL
TronGrid Nilehttps://nile.trongrid.io

Shasta Testnet

ProviderURL
TronGrid Shastahttps://api.shasta.trongrid.io

Node Types

Node TypePropertyPurpose
Full NodefullNodeLatest (unconfirmed) blockchain state, broadcasting transactions
Solidity NodesolidityNodeConfirmed (solidified) blockchain state only
Event ServereventServerSmart contract event queries

Changing Providers at Runtime

// Change full node
tronWeb.setFullNode('https://new-fullnode.example.com');

// Change solidity node
tronWeb.setSolidityNode('https://new-soliditynode.example.com');

// Change event server
tronWeb.setEventServer('https://new-eventserver.example.com');

// Change custom headers
tronWeb.setHeader({ 'TRON-PRO-API-KEY': 'new-api-key' });

Custom Headers

Headers are attached to every HTTP request. Use them for API keys and custom metadata:

const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
headers: {
'TRON-PRO-API-KEY': 'your-api-key',
'Custom-Header': 'value',
},
});

You can retrieve the connected wallet address and TronWeb instance via the TIP-6963 protocol:

window.addEventListener("TIP6963:announceProvider", async (e) => {
// Check if the announced provider is TronLink
if (e.detail.info && e.detail.info.name === "TronLink") {
console.log("You have TronLink installed!");
const tron = e.detail.provider;
const addresses = await tron.request({
method: 'eth_requestAccounts',
});
console.log("Your address: ", addresses[0]);
const tronWeb = tron.tronWeb;
}
});

// Request all TIP-6963 wallets to announce themselves
window.dispatchEvent(new Event("TIP6963:requestProvider"));

Multiple TronWeb Instances

You can create multiple instances for different networks:

// Mainnet instance
const mainnet = new TronWeb({ fullHost: 'https://api.trongrid.io' });

// Testnet instance
const testnet = new TronWeb({ fullHost: 'https://nile.trongrid.io' });

// Use both
const mainBalance = await mainnet.trx.getBalance(address);
const testBalance = await testnet.trx.getBalance(address);

TronGrid API Keys

TronGrid provides free API access with rate limits. For production use, register for an API key:

  1. Visit trongrid.io and create an account
  2. Create an API key in the dashboard
  3. Add the key to your TronWeb configuration:
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
headers: { 'TRON-PRO-API-KEY': 'your-api-key' },
});
PlanRate LimitNotes
FreeLimited QPSSufficient for development
ProHigher QPSFor production applications