Skip to main content

BeL2 SDK

The BeL2 SDK (Software Development Kit) is designed to empower developers to build decentralized applications (DApps) that leverage the capabilities of BeL2. This toolkit provides a set of libraries, tools, and interfaces that simplify the process of integrating Bitcoin functionality into EVM-compatible smart contracts and applications.

Diagram

Purpose and Functionality

The primary purpose of the BeL2 SDK is to provide developers with the necessary tools to interact with the BeL2 system and create innovative cross-chain applications.

  1. The SDK provides interfaces for interacting with BeL2-specific smart contracts, such as the Transaction Verifier Contract.

  2. It includes libraries for verifying zero-knowledge proofs of Bitcoin transactions within EVM-compatible smart contracts.

  3. The SDK offers tools for constructing and signing Bitcoin transactions that can be verified and utilized within the BeL2 ecosystem.

  4. It provides utilities for encoding and decoding data between Bitcoin and EVM-compatible formats.

  5. The SDK includes mechanisms for listening to and processing events from both Bitcoin and EVM-compatible chains.

Importance in the BeL2 Ecosystem

  • It lowers the barrier to entry for developers looking to build cross-chain applications involving Bitcoin and EVM-compatible chains.

  • By providing a standard set of tools and interfaces, the SDK ensures consistency in how developers interact with the BeL2 system.

  • The SDK accelerates the development process by abstracting away complex low-level interactions with different blockchain systems.

Technical Implementation

The BeL2 SDK is implemented as a set of libraries in popular programming languages used for blockchain development, such as JavaScript/TypeScript for web applications and Solidity for smart contracts. Here's a simplified example of how a developer might use the BeL2 SDK in a Typescript application:

import { ZKP } from "@bel2labs/sdk";
import { JsonRpcProvider, Wallet } from "ethers";

type Config = {
chainId: number | bigint;
rpcUrl: string;
privateKey: string;
};

class BeL2BtcTransactionVerification {
private verification!: ZKP.EthersV6.TransactionVerification;
private config: Config;
private provider: JsonRpcProvider;
private signer: Wallet;

constructor(txHash: string, config: Config) {
this.config = config;
this.provider = new JsonRpcProvider(this.config.rpcUrl);
this.signer = new Wallet(this.config.privateKey, this.provider);

// Initialize the verification property asynchronously
this.initializeVerification(txHash);
}

private async initializeVerification(txHash: string): Promise<void> {
this.verification = await ZKP.EthersV6.TransactionVerification.create(
txHash,
this.config.chainId
);
}

public async verifyBitcoinTransaction(): Promise<boolean> {
if (this.verification.isSubmitted()) {
return (
this.verification.isComplete() &&
this.verification.getStatus() ===
ZKP.TransactionVerificationStatus.Verified
);
}

await this.verification.submitVerificationRequest(this.signer);

return new Promise<boolean>((resolve) => {
const subscription = this.verification.status$.subscribe({
next: (status) => {
if (status === ZKP.TransactionVerificationStatus.Verified) {
subscription.unsubscribe();
resolve(true);
} else if (
status === ZKP.TransactionVerificationStatus.VerificationFailed
) {
subscription.unsubscribe();
resolve(false);
}
},
error: (error) => {
console.error("Error in verification status subscription:", error);
subscription.unsubscribe();
resolve(false);
},
});
});
}
}

How It Works with Other Components

The BeL2 SDK is designed to interact with various components of the BeL2 architecture, serving as a bridge between developers and the underlying BeL2 infrastructure:

  1. The SDK provides abstractions for interacting with zkBTC Full Nodes, allowing developers to query Bitcoin transaction data and generate zero-knowledge proofs.
  2. The SDK offers interfaces to submit transaction data and proofs to the Arbitrator Network for relay to EVM-compatible chains.
  3. Developers can use the SDK to interact with the EVM ZKP Contract, submitting proofs for verification and querying the status of verified transactions.
  4. The SDK provides methods to interact with the Transaction Verifier Contract, allowing developers to integrate verified Bitcoin transaction data into their DApps.
  5. The SDK includes tools for developing and deploying smart contracts that can interact with the BeL2 infrastructure on EVM-compatible chains.