Create TRC10 Token on TRON network with nodejs

Nhan Cao
Nhan Cao
Jan 21 · 2 min read

Create TRC20 Token on TRON network with nodejs

About TRC10: https://developers.tron.network/docs/trc10-token

Create TRON wallet with browser extension

Tronlink: https://chrome.google.com/webstore/detail/tronlink/ibnejdfjmmkpcnlpebklmnkoeoihofec

Go to setting, update environment to shasta

Get some TRX for development: https://www.trongrid.io/faucet

Install tronweb: https://developers.tron.network/docs/tron-web-intro

npm i tronweb --save

TRONTokenClient.ts

import TronWeb from 'tronweb'export default class TRONTokenClient {
async start(): Promise<any> {
const mainNetProvider = 'https://api.trongrid.io';
const testNetProvider = 'https://api.shasta.trongrid.io';
const netProvider = testNetProvider;
const HttpProvider = TronWeb.providers.HttpProvider; // Optional provider, can just use a url for the nodes instead
const fullNode = new HttpProvider(`${netProvider}`); // Full node http endpoint
const solidityNode = new HttpProvider(`${netProvider}`); // Solidity node http endpoint
const eventServer = `${netProvider}`; // Contract events http endpoint
const privateKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
);
const defaultTestAddress = tronWeb.address.fromPrivateKey(privateKey);
await this.createTestTRC10Token(tronWeb, defaultTestAddress, privateKey);
// Verify at: https://shasta.tronscan.org/#/
}
async signAndSubmitTx(tronWeb, rawTxObject, privateKey) {
console.log(rawTxObject);
const sign = await tronWeb.trx.sign(rawTxObject, privateKey);
console.log({sign});
const tx = await tronWeb.trx.sendRawTransaction(sign);
// console.log(tx);
return tx;
}
async createTestTRC10Token(tronWeb, issuerAddress, privateKey) {
try {
let options = {
name: 'EricCaoToken',
abbreviation: 'nhancv',
description: 'Nhan Cao Token for Test',
url: 'nhancv.com',
totalSupply: 1000000000,
trxRatio: 1, // How much TRX will tokenRatio cost?
tokenRatio: 1, // How many tokens will trxRatio afford?
saleStart: Date.now() + 10000, // sale start mus > now
saleEnd: Date.now() + 31536000000, // 365 days
freeBandwidth: 0, // The creator's "donated" bandwidth for use by token holders
freeBandwidthLimit: 0, // Out of totalFreeBandwidth, the amount each token holder get
frozenAmount: 0,
frozenDuration: 0
};
const issuerHex = tronWeb.address.toHex(issuerAddress);
const rawTxObj = await tronWeb.transactionBuilder.createToken(options, issuerHex);
// https://shasta.tronscan.org/#/
console.log({rawTxObj});
const res = await this.signAndSubmitTx(tronWeb, rawTxObj, privateKey);
console.log({res});
} catch (e) {
console.error(e);
}
}
}

Note: An account can only issue one asset

Nhan Cao

nhancv.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade