Check Seal Revocation Status
Summary:
The script queries a smart contract deployed on the Hedera network to check the revocation status of a seal using a specific hash. It showcases how to send queries to the smart contract and process the query results.
1. Imports and Environment Setup:
const {
Client,
ContractFunctionParameters,
ContractCallQuery,
Hbar,
PrivateKey
} = require("@hashgraph/sdk");
require('dotenv').config({ path: 'SmartContract_Service/.env' });
It imports necessary modules from the Hedera JavaScript SDK (
@hashgraph/sdk
) and thedotenv
module to load environment variables from a.env
file located in theSmartContract_Service
directory.
2. Environment Variables Retrieval and Validation:
const myAccountId = process.env.MY_ACCOUNT_ID;
const myPrivateKey = PrivateKey.fromString(process.env.MY_PRIVATE_KEY);
const contractId = process.env.CONTRACT_ID;
const hash = process.env.HASH;
if (myAccountId == null || myPrivateKey == null) {
throw new Error("Environment variables myAccountId and myPrivateKey must be present");
}
It 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:
const client = Client.forTestnet();
client.setOperator(myAccountId, myPrivateKey);
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:
async function main() {
const contractCallQuery = new ContractCallQuery()
.setContractId(contractId)
.setGas(100000)
.setFunction("checkSealRevocationStatus", new ContractFunctionParameters().addString(hash))
.setQueryPayment(new Hbar(10));
const contractQuerySubmit = await contractCallQuery.execute(client);
const contractQueryResult = contractQuerySubmit.getBool(0);
console.log("The updated contract message: " + contractQueryResult);
process.exit();
}
It defines the
main()
function, which is the entry point of the script.It creates a query to call the
checkSealRevocationStatus
function of the smart contract with the provided hash parameter.The query is submitted to the Hedera network, and the result (a boolean value indicating the revocation status) is retrieved.
5. Execution:
main();
This line calls the
main()
function to start the execution of the script.
Last updated
Was this helpful?