以下為使用 Node.js 套件 Tron 串接波場區塊鏈 (TRC or TRC20)
可查詢指定錢包地址餘額
const TronWeb = require('tronweb')
const HttpProvider = TronWeb.providers.HttpProvider;
// Full node http endpoint
const fullNode = new HttpProvider('https://api.trongrid.io');
// Solidity node http endpoint
const solidityNode = new HttpProvider('https://api.trongrid.io');
// Contract events http endpoint
const eventServer = 'https://api.trongrid.io/';
// API_KEY 官方可申請: https://developers.tron.network
const privateKey = 'Private_Key';
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
);
async function getBalance() {
const address = '錢包地址';
tronWeb.trx.getBalance(address, (err, balance) => {
if (err)
return console.error(err);
console.log({ balance });
});
}
getBalance();