Skip to content

Instantly share code, notes, and snippets.

@camharris
Created January 12, 2022 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camharris/9037398c0e7509b73d8bbedf1fbb49f4 to your computer and use it in GitHub Desktop.
Save camharris/9037398c0e7509b73d8bbedf1fbb49f4 to your computer and use it in GitHub Desktop.
How to setup rpc endpoints for tronweb
const TronWeb = require('tronweb')
const server = 'SERVER_ADDRESS_GOES_HERE'
const username = 'USERNAME_GOES_HERE';
const password = 'PASSWORD_GOES_HERE';
const rpc_url = (`https://${username}:${password}@${server}`);
// Build out rpc endpoints to be passed as seperate nodes
// since our node provides different endpoints for each tron api
const fullNodeEndpoint = (`${rpc_url}/full`);
const solidityNodeEndpoint = (`${rpc_url}/solidity`);
const eventServerEndpoint = (`${rpc_url}/eventquery`);
const tronWeb = new TronWeb({
fullNode: fullNodeEndpoint,
solidityNode: solidityNodeEndpoint,
eventServer: eventServerEndpoint
})
//Get latest block
tronWeb.trx.getBlock('latest').then(result => {console.log(result)});
//Get wallets balance of some random wallet
// https://tronscan.org/#/address/TZ6tTKBSCvSLD94SxqqZnNNCr3U9rYeMkf
tronWeb.trx.getBalance('TZ6tTKBSCvSLD94SxqqZnNNCr3U9rYeMkf').then(result => {console.log("Balacne of account: TZ6tTKBSCvSLD94SxqqZnNNCr3U9rYeMkf: " + result)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment