Overview
The BeL2 SDK is a powerful toolkit designed to enable developers to integrate Zero-Knowledge Proof (ZKP) functionality for Bitcoin transaction verification on EVM-compatible chains. This overview will help you understand the structure, key components, and main features of the SDK.
SDK Structure
The BeL2 SDK is organized into several modules:
-
ZKP: The main module containing all ZKP-related functionality.
EthersV5
: Provider for Ethers.js v5 compatibility.EthersV6
: Provider for Ethers.js v6 compatibility.
-
Services: Contains various services used by the SDK.
chains
: Defines supported blockchain networks.evm
: Handles EVM-specific operations.nownodes-api
: Interfaces with the NOWNodes API for blockchain data.zkp
: Core ZKP functionality.
-
Utils: Utility functions, including cryptographic operations.
-
Config: Configuration files, including supported EVM chains.
Supported EVM Chains
The BeL2 SDK currently supports the following EVM-compatible chain:
- Elastos Smart Chain (ESC)
- Chain ID: 20
- RPC URL: https://api2.elastos.net/esc
- Explorer: https://esc.elastos.io
- BTC Transaction Verifier Contract: 0x5293a9471A4A004874cea7301aC8936F8830BdF2
This configuration is defined in the src/config/chains.ts
file of the SDK. When using the SDK, you'll need to specify the chain ID (20 for Elastos Smart Chain) when creating a TransactionVerification instance.
Key Components
-
TransactionVerification: The main class for handling Bitcoin transaction verifications.
create
: Static method to create a new verification instance.submitVerificationRequest
: Method to submit a verification request.checkStatus
: Method to check the current status of a verification.status$
: Observable for subscribing to status updates.
-
TransactionVerificationStatus: Enum representing different states of a verification.
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
-
EVM Providers: Support for different versions of Ethers.js (v5 and v6).
Main Features
- Bitcoin Transaction Verification: Submit Bitcoin transactions for verification on EVM chains.
- Status Monitoring: Check and subscribe to verification request statuses.
- Multi-Provider Support: Compatibility with multiple versions of EVM providers.
- Typescript Support: Fully typed for improved developer experience.
Workflow
- Installation: Install the SDK in your project.
- Configuration: Set up the SDK with your preferred EVM provider and network.
- Create Verification: Initialize a verification instance for a Bitcoin transaction.
- Submit Request: Submit a verification request for the transaction.
- Monitor Status: Check or subscribe to status updates for the verification.
Usage Example
Here's a basic example of how to use the BeL2 SDK with the Elastos Smart Chain:
import { ZKP } from "@bel2labs/sdk";
import { ethers } from "ethers";
async function verifyBitcoinTransaction() {
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const txId = "YOUR_BITCOIN_TRANSACTION_ID";
const chainId = 20; // Elastos Smart Chain
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);
}
}
}
verifyBitcoinTransaction();
Next Steps
To start using the BeL2 SDK, follow these guides:
- Installation: Learn how to install the SDK in your project.
- Configuration: Configure the SDK for your specific use case.
- Submit Verification: Learn how to submit a verification request.
- Check Verification Status: Understand how to monitor the status of a verification request.
For a complete list of available methods and their usage, please refer to the API Reference section.
If you encounter any issues or have questions, please consult the Troubleshooting guide or reach out to our support team.