Skip to main content

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:

  1. ZKP: The main module containing all ZKP-related functionality.

    • EthersV5: Provider for Ethers.js v5 compatibility.
    • EthersV6: Provider for Ethers.js v6 compatibility.
  2. 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.
  3. Utils: Utility functions, including cryptographic operations.

  4. Config: Configuration files, including supported EVM chains.

Supported EVM Chains

The BeL2 SDK currently supports the following EVM-compatible chain:

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

  1. 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.
  2. TransactionVerificationStatus: Enum representing different states of a verification.

    • Unknown: Status hasn't been retrieved yet
    • NotSubmitted: Transaction has never been submitted for ZKP verification
    • Pending: Transaction has been submitted for ZKP verification to the ZKP contract, but proof generation has not been handled or completed yet
    • Verified: Transaction proof has been successfully created and is ready to be checked from EVM smart contracts
    • VerificationFailed: Failure during verification
  3. EVM Providers: Support for different versions of Ethers.js (v5 and v6).

Main Features

  1. Bitcoin Transaction Verification: Submit Bitcoin transactions for verification on EVM chains.
  2. Status Monitoring: Check and subscribe to verification request statuses.
  3. Multi-Provider Support: Compatibility with multiple versions of EVM providers.
  4. Typescript Support: Fully typed for improved developer experience.

Workflow

  1. Installation: Install the SDK in your project.
  2. Configuration: Set up the SDK with your preferred EVM provider and network.
  3. Create Verification: Initialize a verification instance for a Bitcoin transaction.
  4. Submit Request: Submit a verification request for the transaction.
  5. 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:

  1. Installation: Learn how to install the SDK in your project.
  2. Configuration: Configure the SDK for your specific use case.
  3. Submit Verification: Learn how to submit a verification request.
  4. 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.