Applied Blockchain Center (ABC)
  • System requirements for ABC
  • Hedera
    • 🅰️About Hedera
    • 🖥️Environment Setup
    • Tutorials
      • Accounts
        • Get My Account Info
        • Get Other Account Info
        • Transfer HBAR
      • Consensus Service
        • Create Topic
        • Subscribe to a topic
        • Submit a message
      • File Service
        • Create a File
        • Retrieve File
      • Scheduled_TX
        • Create Scheduled Transaction
        • Scheduled Transaction Info
        • Delete Scheduled Transaction
        • Submit Signature
      • SmartContract Service
        • Deploy to Hedera
        • Seal Document
        • Get Seal
        • Check Seal Revocation Status
        • Revoke Document
      • Token Service
        • Fungible Token
        • Non-fungible Token
  • Hyperledger Fabric
    • 📑About Hyperledger Fabric
    • 💻Prerequisite Installation
    • Fabric Installation
      • 🧪Installation & Test
      • ✈️Launch Network
      • ⛓️Channel Creation
      • 🚚Chaincode Deployment
      • ▶️Chaincode Execution
  • Hyperledger Besu
    • Besu Network Set
Powered by GitBook
On this page
  • Summary:
  • Step 1: Imports and Environment Setup
  • Step 2: Environment Variables Retrieval and Validation
  • Step 3: Client Setup
  • Step 4: Main Function
  • Step 5: Execution:

Was this helpful?

  1. Hedera
  2. Tutorials
  3. Scheduled_TX

Delete Scheduled Transaction

Summary:

This script deletes a scheduled transaction on the Hedera network using its schedule ID. It demonstrates how to use the ScheduleDeleteTransaction to create a transaction for deleting a scheduled transaction, sign it with the admin key, execute it on the Hedera network, and retrieve the transaction status to confirm the deletion operation

Step 1: Imports and Environment Setup

const {
    ScheduleDeleteTransaction,
    Client,
    PrivateKey
} = require("@hashgraph/sdk");
require('dotenv').config({ path: 'Scheduled_TX/.env' });
  • The script imports necessary modules from the Hedera JavaScript SDK (@hashgraph/sdk): ScheduleDeleteTransaction, Client, and PrivateKey.

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

Step 2: Environment Variables Retrieval and Validation

const myAccountId = process.env.MY_ACCOUNT_ID;
const myPrivateKey = PrivateKey.fromString(process.env.MY_PRIVATE_KEY);

const scheduleId = process.env.SCHEDULE_ID;

if (myAccountId == null ||
    myPrivateKey == null ) {
    throw new Error("Environment variables myAccountId and myPrivateKey must be present");
}
  • The code retrieves necessary environment variables such as account ID and private key from the .env file.

  • It validates that the required environment variables (MY_ACCOUNT_ID and MY_PRIVATE_KEY) are present. If not, it throws an error.

Step 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.

Step 4: Main Function

async function main() {
    const transaction = await new ScheduleDeleteTransaction()
        .setScheduleId(scheduleId)
        .freezeWith(client)
        .sign(myPrivateKey);

    const txResponse = await transaction.execute(client);

    const receipt = await txResponse.getReceipt(client);

    const transactionStatus = receipt.status;
    console.log("The transaction consensus status is " +transactionStatus);

    process.exit();
}
  • This is the main function named main().

  • It creates a ScheduleDeleteTransaction instance to delete the scheduled transaction using the provided schedule ID.

  • The transaction is frozen with the client, signed with the admin key (private key), and executed using the client.

  • The script then retrieves the receipt of the transaction to obtain its status, which indicates the consensus status of the deletion operation.

  • The transaction consensus status is logged to the console.

Step 5: Execution:

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

PreviousScheduled Transaction InfoNextSubmit Signature

Last updated 1 year ago

Was this helpful?