Skip to main content

cnft.cancelContract(CancelContract)

Cancel a Contract NFT draft. This sends a transaction from the contract controller and removes the draft from storage.

CancelContract Type Parameters

ParameterTypeRequiredDescription
contractControllerSignerRequiredContract controller signer authorized to cancel the contract. Must be connected to a provider.
contractNftstringRequiredContract NFT contract address.
contractIdstringRequiredContract ID to cancel.

Returns

FieldTypeDescription
statuscancelledStatus of the operation.
contractNftstringContract NFT contract address.
contractIdstringContract ID that was cancelled (from emitted event).
cancelledBystringController address that submitted the transaction.
receiptTransactionReceiptTransaction receipt for the cancellation call.

Usage

TypeScript

import 'dotenv/config';
import { RWA, Chain, type SDKInit } from '@peaq-network/rwa';
import { JsonRpcProvider, Wallet, keccak256, toUtf8Bytes } from 'ethers';

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const init: SDKInit = { chainId: Chain.AGUNG, provider: provider };
  const rwa_sdk = new RWA(init);

  // 1. Contract controller
  const alice = new Wallet(process.env.ALICE_PRIVATE_KEY!, provider);

  // 2. Get contract draft
  const contractNft = "0x35D67095A5a6f00CBE288cF744b3efC48de3699a";
  const contractId - "1234567890"

  // 3. Cancel the contract
  const result = await rwa_sdk.cnft.cancelContract({
    contractController: alice,
    contractNft: contractNft,
    contractId: contractId
  });
  console.log("Result", result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

JavaScript

import 'dotenv/config';
import { RWA, Chain } from '@peaq-network/rwa';
import { JsonRpcProvider, Wallet, keccak256, toUtf8Bytes } from 'ethers';

async function main() {
  // 0. Create RWA instance and get provider
  const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
  const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider });

  // 1. Contract controller and counterparties
  const alice = new Wallet(process.env.ALICE_PRIVATE_KEY, provider);

  // 2. Get contract draft
  const contractNft = "0x35D67095A5a6f00CBE288cF744b3efC48de3699a";
  const contractId = "1234567890"

  // 3. Cancel the contract
  const result = await rwa_sdk.cnft.cancelContract({
    contractController: alice,
    contractNft: contractNft,
    contractId: contractId
  });
  console.log("Result", result);
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

Example outputs

Result {
  status: 'cancelled',
  contractNft: '0x35D67095A5a6f00CBE288cF744b3efC48de3699a',
  contractId: '1234567890',
  cancelledBy: '0x16cd4D21537eD8F33bE08271A9FA6DCC426709b2',
  receipt: ContractTransactionReceipt {
    ...
  }
}
Note: Once cancelled, getDraft for the same contractId will revert with Not found.