--- sidebar_position: 3 title: Provider Configuration description: "Covers TronWeb provider configuration: fullHost vs individual nodes, mainnet/Nile/Shasta endpoints, runtime switching, custom headers, TronLink, and API keys." keywords: ["provider configuration", "tronweb", "fullhost", "fullnode", "trongrid", "api key"] --- # Provider Configuration TronWeb supports flexible node provider configuration for connecting to different TRON networks and custom nodes. ## Basic Configuration ### Using fullHost (Recommended) The simplest configuration — uses the same URL for all services: ```javascript 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: ```javascript 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 | Provider | URL | |----------|-----| | TronGrid | `https://api.trongrid.io` | | Custom node | Your self-hosted Full Node URL | ### Nile Testnet | Provider | URL | |----------|-----| | TronGrid Nile | `https://nile.trongrid.io` | ### Shasta Testnet | Provider | URL | |----------|-----| | TronGrid Shasta | `https://api.shasta.trongrid.io` | ## Node Types | Node Type | Property | Purpose | |-----------|----------|---------| | **Full Node** | `fullNode` | Latest (unconfirmed) blockchain state, broadcasting transactions | | **Solidity Node** | `solidityNode` | Confirmed (solidified) blockchain state only | | **Event Server** | `eventServer` | Smart contract event queries | ## Changing Providers at Runtime ```javascript // 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: ```javascript const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io', headers: { 'TRON-PRO-API-KEY': 'your-api-key', 'Custom-Header': 'value', }, }); ``` ## Using with TronLink You can retrieve the connected wallet address and TronWeb instance via the TIP-6963 protocol: ```javascript 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: ```javascript // 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](https://www.trongrid.io/) provides free API access with rate limits. For production use, register for an API key: 1. Visit [trongrid.io](https://www.trongrid.io/) and create an account 2. Create an API key in the dashboard 3. Add the key to your TronWeb configuration: ```javascript const tronWeb = new TronWeb({ fullHost: 'https://api.trongrid.io', headers: { 'TRON-PRO-API-KEY': 'your-api-key' }, }); ``` | Plan | Rate Limit | Notes | |------|------------|-------| | Free | Limited QPS | Sufficient for development | | Pro | Higher QPS | For production applications |