Created
January 12, 2022 22:36
-
-
Save camharris/9037398c0e7509b73d8bbedf1fbb49f4 to your computer and use it in GitHub Desktop.
How to setup rpc endpoints for tronweb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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