Skip to main content

Submitting a Verification Request

Once you have configured the BeL2 SDK, you can submit a verification request for a Bitcoin transaction. This guide will walk you through the process of submitting a verification request using the SDK.

Prerequisites

Before submitting a verification request, ensure that you have:

  1. Installed and configured the BeL2 SDK
  2. Set up an EVM provider (e.g., Ethers.js)
  3. Obtained a signer (e.g., connected to MetaMask or another wallet)

Submitting a Verification Request

Here's a step-by-step guide to submit a verification request:

  1. Import the necessary modules:
import { ZKP } from "@bel2labs/sdk";
import { ethers } from 'ethers';
  1. Set up the provider and signer:
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
  1. Create a TransactionVerification instance:
const txId = 'YOUR_BITCOIN_TRANSACTION_ID';
const chainId = 20; // Replace with your target EVM chain ID

const verification = await ZKP.EthersV6.TransactionVerification.create(txId, chainId);
  1. Submit the verification request:
if (!verification.isSubmitted()) {
try {
const response = await verification.submitVerificationRequest(signer);
console.log("Verification request submitted:", response);
} catch (error) {
console.error("Error submitting verification request:", error);
}
}
  1. (Optional) Subscribe to status updates:
verification.status$.subscribe((status) => {
console.log("New status:", status);
});

Full Example

Here's a complete example of submitting a verification request:

import { ZKP } from "@bel2labs/sdk";
import { ethers } from 'ethers';

async function submitVerification() {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

const txId = 'YOUR_BITCOIN_TRANSACTION_ID';
const chainId = 20; // Replace with your target EVM chain ID

const verification = await ZKP.EthersV6.TransactionVerification.create(txId, chainId);

verification.status$.subscribe((status) => {
console.log("New status:", status);
});

if (!verification.isSubmitted()) {
try {
const response = await verification.submitVerificationRequest(signer);
console.log("Verification request submitted:", response);
} catch (error) {
console.error("Error submitting verification request:", error);
}
} else {
console.log("Verification request already submitted");
}
}

submitVerification();

Understanding the Response

The submitVerificationRequest method returns a transaction hash. This hash can be used to track the transaction on the EVM network.

Next Steps

After submitting a verification request, you may want to:

  1. Check the verification status to monitor the progress of your request.
  2. Handle any errors that may occur during the submission process.
  3. Implement a user interface to display the verification status to your users.

Remember to always handle errors and edge cases in your production code to ensure a smooth user experience.

If you encounter any issues while submitting verification requests, please refer to the Troubleshooting section or reach out to our support team.