Seal Document

Summary:

The script interacts with a deployed smart contract on the Hedera network by executing a function call and decoding the emitted events. It showcases how to send transactions to the smart contract and parse the resulting event data.

1. Imports and Environment Setup:

const {
    Client,
    ContractFunctionParameters,
    ContractExecuteTransaction,
    PrivateKey,
} = require("@hashgraph/sdk");
require('dotenv').config({ path: 'SmartContract_Service/.env' });

const Web3 = require('web3');
const web3 = new Web3;
let abi;
  • It imports necessary modules from the Hedera JavaScript SDK (@hashgraph/sdk), including Client, ContractFunctionParameters, ContractExecuteTransaction, and PrivateKey.

  • It also imports the dotenv module to load environment variables from a .env file located in the SmartContract_Service directory.

  • The script imports the Web3 module to interact with the Ethereum-like smart contract and creates a web3 instance.

2. Environment Variables Retrieval and Validation:

  • The script retrieves the account ID, private key, contract ID, and hash from the .env file.

  • It checks whether these variables are present; otherwise, it throws an error.

3. Client Setup:

  • It creates a client instance for the Hedera testnet and sets the operator account using the user's account ID and private key.

4. Main Function:

  • The main() function is the entry point of the script.

  • It creates a transaction to execute a function (seal) on the smart contract with the given contract ID and hash parameter.

  • The transaction is executed on the Hedera network, and its receipt is retrieved to confirm the execution status.

  • Events emitted by the smart contract function call are parsed and decoded using the decodeEvent function.

5. Event Decoding Function:

  • The decodeEvent function decodes the event contents using the ABI definition of the event.

  • It loads the ABI file of the smart contract and finds the event ABI based on the event name.

  • The event data is decoded using web3.eth.abi.decodeLog.

6. Execution:

  • This line calls the main() function to start the execution of the script.

Last updated

Was this helpful?