Loading...
This SmartBook will discuss about different methods tronweb provides us to get account details of specific address
You can refer this smartbook for detailed project initiation with tronweb.
const TronWeb = require('tronweb')
const tronWeb = new TronWeb({
//fullHost: 'https://api.trongrid.io', // For Mainnet
fullHost : 'https://api.shasta.trongrid.io', // For Shasta testnet
headers : { "TRON-PRO-API-KEY": 'your api key' },
privateKey : 'your private key'
});
This function will give detailed information about specified address
Syntax :
tronWeb.trx.getAccount(address)
Parameter :
Returns : Account details object.
Example :
//Parameter Base58
tronWeb.trx.getAccount('41BF97A54F4B829C4E9253B26024B1829E1A3B1120').then(result => console.log(result));
//or
//Parameter HexString
tronWeb.trx.getAccount('TTSFjEG3Lu9WkHdp4JrWYhbGP6K1REqnGQ').then(result => console.log(result));
Output :
> {
address: '41bf97a54f4b829c4e9253b26024b1829e1a3b1120',
balance: 29887074430,
frozen: [ { frozen_balance: 12000000, expire_time: 1577615814000 } ],
create_time: 1575710031000,
latest_opration_time: 1577356614000,
latest_consume_free_time: 1577356614000,
account_resource: {
frozen_balance_for_energy: { frozen_balance: 12000000, expire_time: 1577588400000 },
latest_consume_time_for_energy: 1577342304000
},
owner_permission: { permission_name: 'owner', threshold: 1, keys: [ [Object] ] },
active_permission: [
{
type: 'Active',
id: 2,
permission_name: 'active',
threshold: 1,
operations: '7fff1fc0033e0100000000000000000000000000000000000000000000000000',
keys: [Array]
}
],
assetV2: [ { key: '1000001', value: 0 } ],
free_asset_net_usageV2: [ { key: '1000001', value: 0 } ]
}
This will give the account's bandwidth and energy resources.
Syntax :
tronWeb.trx.getAccountResources(address);
Parameters :
Returns : Account resources object.
Example :
//Parameter Base58
tronWeb.trx.getAccountResources('TTSFjEG3Lu9WkHdp4JrWYhbGP6K1REqnGQ').then(result => console.log(result));
//or
//Parameter HexString
tronWeb.trx.getAccountResources('41BF97A54F4B829C4E9253B26024B1829E1A3B1120').then(result => console.log(result));
Output :
> {
freeNetLimit: 5000,
NetLimit: 483512,
assetNetUsed: [ { key: '1000001', value: 0 } ],
assetNetLimit: [ { key: '1000001', value: 0 } ],
TotalNetLimit: 43200000000,
TotalNetWeight: 1072155,
EnergyLimit: 4949344,
TotalEnergyLimit: 971444468045,
TotalEnergyWeight: 2355329
}
It will give the account's balance of TRX in SUN
Syntax :
tronWeb.trx.getBalance(address);
Parameters :
Returns : Balance as a number in SUN.
Example :
//Parameter Base58
tronWeb.trx.getBalance('TTSFjEG3Lu9WkHdp4JrWYhbGP6K1REqnGQ').then(result => console.log(result));
//or
//Parameter HexString
tronWeb.trx.getBalance('41BF97A54F4B829C4E9253B26024B1829E1A3B1120').then(result => console.log(result));
Output :
> 29887074430