I want to create a TRON web wallet but I am a complete noob. My first question is how do I generate addresses offline and with a private master key or with a mnemonic seed. The second question is how can I query the balance of all addresses generated by me with a single request to TronGrid?
-
CHeck https://developers.tron.network/docs/trongridjs. – Richard Rublev Mar 16 '21 at 09:02
-
I checked but I did not found anything for generating a mnemonic seed – ADLZ Mar 16 '21 at 11:29
3 Answers
Assuming you have TronWeb
installed.
You can do TronWeb.createAccount()
to generate an address and save the output, example from docs.
You may need to check balance of address one by one by posting to TronGrid, https://api.trongrid.io/wallet/getaccount
, example from docs

- 729
- 3
- 10
-
that's not an option. it requires me to have an external wallet. I don't need one, instead i want nodejs to be the manager of crypto adresses that is a wallet – Kirill Aug 17 '23 at 16:18
Step 1 - npm install ton web and crypto lib
const TronWeb = require('tronweb');
var crypto = require('crypto');
Step 2 - Generate random private key and use the private key to create tronweb account
var privateKey = crypto.randomBytes(32).toString('hex');
console.log("Private Key", privateKey);
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
const wallet = await tronWeb.createAccount();
console.log(wallet);
Step 3 - result
{
privateKey: 'D526E0AB73B3552F0B0FB85838DB364D90C1CAC4BC76294373FABA83C04914DD',
publicKey: '04CA86DEFC9C8828DB52DBF6DD44872DE863AC53126B9D49260AB677CB0B9A18BC0276A58DAC04928AEDDAC85B8CFDFA8A8536832735BD8C5E0AE84BE2E505D83F',
address: {
base58: 'TVFFvcUB6CWLFh45n28Ve1XRmu1NYSKS34',
hex: '41D3737C4D6B5105692B01409738D29CD796876602'
}
}
Generate a random mnemonic (total number 12) and using TRON path "m/44'/195'" by default, return the 0th account address and private key
tronWeb.createRandom()
{
"mnemonic": {
"phrase": "chimney cloth deny claim play rude love dose apart shove rack stone",
"path": "m/44'/195'/0'/0/0",
"locale": "en"
},
"privateKey": "0x79092289f3bfde55f079202e3642b2c4ba071d5f0b85d65b1919c8724e94848c",
"publicKey": "0x0421c47d627bc2d856760dda17b42b726b4bc8f5def76aed0cbcd71566d0ffedfc3904c9c854854a5019b8373d2aed0c6b96ff5f3be07722403088742b0949a6c9",
"address": "TEFAyPnainfiAJBuhExfMLJeHHxD2DZJmF",
}

- 412
- 8
- 19
1- install tronweb npm package:
npm i tronweb
2- use this example:
// create tronweb client
const TronWeb = require('tronweb');
const fullNode = 'https://api.shasta.trongrid.io';
const solidityNode = 'https://api.shasta.trongrid.io';
const eventServer = 'https://api.shasta.trongrid.io';
const privateKey = 'xxx';
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
// create new account
const account = tronWeb.createAccount();
//IMPORTANT: don't forget to encrypt account private key before store
//and don't forget clear variable[memory!]
//account result example::
//{ address: {
// base58: "TPbBpRXnt6ztse8XkCLiJstZyqQZvxW2sx",
//hex: "4195679F3AAF5211991781D49B30525DDDFE9A18DE"}
//privateKey: "08089C24EC3BAEB34254DDF5297CF8FBB8E031496FF67B4EFACA738FF9EBD455"
//publicKey: "04EE63599802B5D31A29C95CC7DF04F427E8F0A124BED9333F3A80404ACFC3127659C540D0162DEDB81AC5F74B2DEB4962656EFE112B252E54AC3BA1207CD1FB10" }
for more info visit tronweb documentation: tronweb documentation
for other programming languages and platforms use TRON FULL NODE API
for encrypt the private key visit this answer

- 81
- 1
- 3