-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (46 loc) · 2.59 KB
/
index.js
File metadata and controls
56 lines (46 loc) · 2.59 KB
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
console.clear();
import { Client, AccountId, PrivateKey, Hbar, ContractFunctionParameters } from "@hashgraph/sdk";
import dotenv from "dotenv";
dotenv.config();
import * as queries from "./utils/queries.js";
import * as contracts from "./utils/contractOperations.js";
import counterContract from "./contracts/Counter.json" assert { type: "json" };
import counterCallerContract from "./contracts/CounterCaller.json" assert { type: "json" };
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromString(process.env.OPERATOR_PVKEY);
const network = process.env.HEDERA_NETWORK;
const client = Client.forNetwork(network).setOperator(operatorId, operatorKey);
client.setDefaultMaxTransactionFee(new Hbar(1000));
client.setMaxQueryPayment(new Hbar(50));
async function main() {
// STEP 1 ===================================
console.log(`\nSTEP 1 ===================================\n`);
console.log(`- Deploying contracts...\n`);
// Deploy the called contract (counter)
let gasLim = 8000000;
const bytecode = counterContract.object;
const params = [];
const [calledContractId, calledContractAddress] = await contracts.deployContractFcn(bytecode, params, gasLim, client);
console.log(`- Contract ID: ${calledContractId}`);
console.log(`- Contract ID in Solidity address format: ${calledContractAddress}`);
// Deploy the caller contract (counter caller)
const bytecode1 = counterCallerContract.object;
const params1 = new ContractFunctionParameters().addAddress(calledContractAddress);
const [callerContractId, callerContractAddress] = await contracts.deployContractFcn(bytecode1, params1, gasLim, client);
console.log(`- Contract ID: ${callerContractId}`);
console.log(`- Contract ID in Solidity address format: ${callerContractAddress}`);
// STEP 2 ===================================
console.log(`\nSTEP 2 ===================================\n`);
console.log(`- Executing the caller contract...\n`);
// Execute the contract
const contractExecuteRec = await contracts.executeContractFcn(callerContractId, "counterIncrement", gasLim, client);
console.log(`- Contract execution: ${contractExecuteRec.receipt.status} \n`);
// Check a Mirror Node Explorer
const [randNumInfo, randNumExpUrl] = await queries.mirrorTxQueryFcn(contractExecuteRec, network);
console.log(`\n- See details in mirror node explorer: \n${randNumExpUrl}`);
console.log(`
====================================================
🎉🎉 THE END - NOW JOIN: https://hedera.com/discord
====================================================\n`);
}
main();