Skip to main content
Version: 6.2.0

Account creation

This is a tutorial about how to create an account using TronWeb.

1. Generate an account​

First, you need to use tronWeb.createAccount() to create an account.

const account = await tronWeb.createAccount();

2. Activate the account​

After creating an account, you need to activate it. First, use your already exist account to instantiate TronWeb. Then, use tronWeb.trx.sendTrx() to send a TRX to the account.

const transaction = await tronWeb.trx.sendTrx(
account.address,
1000000
);

You can also use tronWeb.transactionBuilder.createAccount(account.address), then sign the transaction and broadcast it.

const tx = await tronWeb.transactionBuilder.createAccount(account.address);
const signTx = await tronWeb.trx.sign(tx);
const receipt = await tronWeb.trx.sendRawTransaction(signTx);

3. Compute address from public key​

You may need to compute the TRON address from publick key. Here's the method:

const pubkey = tronWeb.utils.code.hexStr2byteArray(account.publicKey.replace(/^0x/, ''));
const addressBytes = tronWeb.utils.crypto.computeAddress(pubkey);
const addressHex = tronWeb.utils.bytes.byteArray2hexStr(addressBytes);

For infomation about account model, go here.