-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.ts
62 lines (60 loc) · 2.17 KB
/
token.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//@ts-ignore
import * as TronWeb from "tronweb";
export default class TRONTokenClient {
// @ts-ignore
async start(): Promise<any> {
const testNetProvider = 'https://api.shasta.trongrid.io';
const netProvider = testNetProvider;
const fullNode = netProvider;
const solidityNode = netProvider;
const eventServer = netProvider;
const privateKey = 'PK_TEST_WALLET';
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:any, rawTxObject:any, privateKey:any) {
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:any, issuerAddress:any, privateKey:any) {
try {
let options = {
name: 'Name',
abbreviation: 'TTT',
description: 'Description',
url: 'testtoken.com',
totalSupply: 1000000000,
trxRatio: 1,
tokenRatio: 1,
saleStart: Date.now() + 10000,
saleEnd: Date.now() + 31536000000,
freeBandwidth: 0,
freeBandwidthLimit: 0,
frozenAmount: 0,
frozenDuration: 0
};
const issuerHex = tronWeb.address.toHex(issuerAddress);
const rawTxObj = await tronWeb.transactionBuilder.createToken(options, issuerHex);
console.log({rawTxObj});
const res = await this.signAndSubmitTx(tronWeb, rawTxObj, privateKey);
console.log({res});
} catch (e) {
console.error(e);
}
}
}
(() => {
const token = new TRONTokenClient();
token.start().then(r => console.log("ll ", r));
})();