-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestnet.js
115 lines (73 loc) · 2.47 KB
/
testnet.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* allow us to use our .env variables */
//require("dotenv").config();
import {
Wallet,
LocalProvider,
Client,
TokenCreateTransaction,
PrivateKey,
AccountId,
PublicKey,
TransactionId,
Timestamp,
} from "@hashgraph/sdk";
import * as hex from "./hex.js";
import dotenv from "dotenv";
dotenv.config();
/* import the Hedera JavaScript SDK */
//const { Client, CryptoTransferTransaction } = require("@hashgraph/sdk");
/* create a new asynchronous function */
async function main() {
try {
// testnet
var account_id = AccountId.fromString("0.0.45949322")
var public_key = PublicKey.fromString("302a300506032b657003210009fc854d1005984c386206cc68382900a0f9647d7a0ddd164d27f9dcd767f1f6")
var private_key = PrivateKey.fromString("302e020100300506032b657004220420c26e9b65de501380d105634579077492fd59b8614b0aedb55410b20a47469f28");
/* configure our testnet client */
const client = Client.forTestnet();
client.setOperator(account_id, private_key);
const wallet = new Wallet(
account_id,
private_key,
new LocalProvider()
);
const now = Date.now();
const seconds = Math.floor(now / 1000); // + 15mins
const validStart = new Timestamp(seconds, 0);
const transactionId = new TransactionId(
account_id,
validStart,
false
);
console.log('txid');
console.log(transactionId.toString());
var tokenCreateTransaction = await new TokenCreateTransaction()
.setTransactionId(transactionId)
.setTokenName("namtestjs")
.setTokenSymbol("namtestjs")
.setDecimals(3)
.setInitialSupply(0)
.setTreasuryAccountId(account_id)
.setAdminKey(public_key)
.setFreezeKey(public_key)
.setSupplyKey(public_key)
.freezeWith(client)
// how to decode
// transaction = Transaction.fromBytes(transaction.toBytes());
const txbyte = tokenCreateTransaction.toBytes();
console.log("txbytes");
console.log(txbyte);
var txbyte_str = hex.encode(txbyte.toString());
//console.log({ "transaction": txbyte_str });
tokenCreateTransaction = await tokenCreateTransaction.signWithSigner(wallet);
var resp = await tokenCreateTransaction.executeWithSigner(wallet);
const receipt = await resp.getReceiptWithSigner(wallet);
console.log(resp);
console.log(receipt)
// https://testnet.dragonglass.me/hedera/tokens/0.0.48704913
} catch (err) {
console.log(err);
}
}
/* call our async function */
void main();