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:
- Installed and configured the BeL2 SDK
- Set up an EVM provider (e.g., Ethers.js)
- 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:
- Import the necessary modules:
import { ZKP } from "@bel2labs/sdk";
import { ethers } from 'ethers';
- Set up the provider and signer:
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
- 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);
- 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);
}
}
- (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:
- Check the verification status to monitor the progress of your request.
- Handle any errors that may occur during the submission process.
- 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.