forked from cisc0f/hedera
-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy.js
73 lines (55 loc) · 2.36 KB
/
deploy.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
const {
Client,
AccountId,
PrivateKey,
ContractCreateFlow,
ContractFunctionParameters,
ContractExecuteTransaction,
AccountCreateTransaction,
Hbar
} = require('@hashgraph/sdk');
const fs = require('fs');
require('dotenv').config({path: __dirname + '/../../.env'});
// Get operator from .env file
const operatorKey = PrivateKey.fromString(process.env.PRIVATE_KEY);
const operatorId = AccountId.fromString(process.env.ACCOUNT_ID);
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
// Account creation function
async function accountCreator(pvKey, iBal) {
const response = await new AccountCreateTransaction()
.setInitialBalance(new Hbar(iBal))
.setKey(pvKey.publicKey)
.execute(client);
const receipt = await response.getReceipt(client);
return receipt.accountId;
}
const main = async () => {
const treasuryKey = PrivateKey.generateED25519();
const treasuryId = await accountCreator(treasuryKey, 10);
const bytecode = fs.readFileSync('./binaries/TokenCreator_sol_TokenCreator.bin');
const createContract = new ContractCreateFlow()
.setGas(150000) // Increase if revert
.setBytecode(bytecode); // Contract bytecode
const createContractTx = await createContract.execute(client);
const createContractRx = await createContractTx.getReceipt(client);
const contractId = createContractRx.contractId;
console.log(`Contract created with ID: ${contractId}`);
// Create FT using precompile function
const createToken = new ContractExecuteTransaction()
.setContractId(contractId)
.setGas(300000) // Increase if revert
.setPayableAmount(20) // Increase if revert
.setFunction("createFungible",
new ContractFunctionParameters()
.addString("USD Bar") // FT name
.addString("USDB") // FT symbol
.addUint256(1000000000) // FT initial supply
.addUint256(2) // FT decimals
.addUint32(7000000)); // auto renew period
const createTokenTx = await createToken.execute(client);
const createTokenRx = await createTokenTx.getRecord(client);
const tokenIdSolidityAddr = createTokenRx.contractFunctionResult.getAddress(0);
const tokenId = AccountId.fromSolidityAddress(tokenIdSolidityAddr);
console.log(`Token created with ID: ${tokenId} \n`);
}
main();