Checking Verification Status
After submitting a verification request, you'll want to monitor its status. The BeL2 SDK provides methods to check the current status of a verification request and to subscribe to status updates. This guide will walk you through the process of checking and monitoring the verification status.
Prerequisites
Before checking the verification status, ensure that you have:
- Installed and configured the BeL2 SDK
- Submitted a verification request (see Submitting a Verification Request)
Checking the Current Status
You can check the current status of a verification request using the checkStatus
method:
import { ZKP } from "@bel2labs/sdk";
import { ethers } from "ethers";
async function checkVerificationStatus() {
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
);
try {
await verification.checkStatus();
console.log("Current status:", verification.status$.getValue());
} catch (error) {
console.error("Error checking status:", error);
}
}
checkVerificationStatus();
Subscribing to Status Updates
To continuously monitor the status of a verification request, you can subscribe to status updates:
import { ZKP } from "@bel2labs/sdk";
import { ethers } from "ethers";
async function monitorVerificationStatus() {
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);
// Handle the new status (e.g., update UI, trigger actions)
},
(error) => {
console.error("Error in status subscription:", error);
}
);
}
monitorVerificationStatus();
Understanding Verification Statuses
The verification status can be one of the following:
Unknown
: Status hasn't been retrieved yetNotSubmitted
: Transaction has never been submitted for ZKP verificationPending
: Transaction has been submitted for ZKP verification to the ZKP contract, but proof generation has not been handled or completed yetVerified
: Transaction proof has been successfully created and is ready to be checked from EVM smart contractsVerificationFailed
: Failure during verification
You can import these status values from the SDK:
import { ZKP } from "@bel2labs/sdk";
const { TransactionVerificationStatus } = ZKP;
console.log(TransactionVerificationStatus.Unknown);
console.log(TransactionVerificationStatus.NotSubmitted);
console.log(TransactionVerificationStatus.Pending);
console.log(TransactionVerificationStatus.Verified);
console.log(TransactionVerificationStatus.VerificationFailed);
Handling Different Statuses
You might want to perform different actions based on the verification status. Here's an example of how you could handle different statuses:
verification.status$.subscribe((status) => {
switch (status) {
case TransactionVerificationStatus.Unknown:
console.log("Verification not retrieved yet");
// Prompt user to submit a verification request
break;
case TransactionVerificationStatus.NotSubmitted:
console.log("Transaction never submitted for ZKP verification");
// Prompt user to submit a verification request
break;
case TransactionVerificationStatus.Pending:
console.log(
"Transaction submitted for ZKP verification, but proof generation not hadled nor completed yet"
);
// Update progress indicator
break;
case TransactionVerificationStatus.Verified:
console.log(
"Transaction proof successfully created and ready to be checked from EVM smart contract"
);
// Show success message, enable further actions
break;
case TransactionVerificationStatus.VerificationFailed:
console.log("Transaction failed verification");
// Show error message
break;
default:
console.log("Unknown status:", status);
}
});
Error Handling
When checking the status or subscribing to updates, make sure to implement proper error handling:
try {
await verification.checkStatus();
} catch (error) {
console.error("Error checking status:", error);
// Handle the error (e.g., show error message to user, retry)
}
verification.status$.subscribe(
(status) => {
console.log("New status:", status);
},
(error) => {
console.error("Error in status subscription:", error);
// Handle the error (e.g., show error message to user, resubscribe)
}
);
Best Practices
-
Polling Interval: If you're repeatedly checking the status, consider implementing a reasonable polling interval (e.g., every 30 seconds) to avoid overwhelming the network.
-
Unsubscribing: If you're using the subscription method, make sure to unsubscribe when appropriate (e.g., when component unmounts in a React application) to prevent memory leaks.
-
UI Updates: Update your user interface based on status changes to keep users informed about the verification progress.
-
Error Recovery: Implement retry mechanisms for temporary errors and provide clear feedback to users about any issues.
Next Steps
Now that you know how to check and monitor verification status, you can:
- Implement a complete verification workflow in your application.
- Develop a user interface that reflects the current verification status.
- Handle different verification outcomes in your business logic.
If you encounter any issues while working with verification statuses, please refer to the Troubleshooting section or reach out to our support team.