Skip to main content

Configuration

After installing the BeL2 SDK, you need to configure it for your specific use case. This guide will walk you through the process of setting up the SDK with your preferred EVM provider and network.

Supported EVM Chain

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.

Choosing an EVM Provider

The BeL2 SDK supports multiple versions of popular EVM providers. Currently, it supports:

  • Ethers.js v5
  • Ethers.js v6

We recommend using Ethers.js v6 for the latest features and improvements. Here's how to set up the SDK with Ethers.js v6:

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

// For browser environments (e.g., MetaMask)
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

// For Node.js environments or direct RPC connection
const provider = new ethers.JsonRpcProvider("https://api2.elastos.net/esc");
const signer = new ethers.Wallet("YOUR_WALLET_ACCOUNT_PRIVATE_KEY", provider);
note

There are slight differences handling the configuration regarding the app type and the Ethers.js version chosen.

You can find implementation examples below:

Creating a Transaction Verification Instance

To start using the ZKP functionality, you need to create a TransactionVerification instance:

const txId = "YOUR_BITCOIN_TRANSACTION_ID";
const chainId = 20; // Elastos Smart Chain

const verification = await ZKP.EthersV6.TransactionVerification.create(
txId,
chainId
);

The create method initializes the verification process and checks the current status of the verification.

Configuring Status Updates

You can subscribe to status updates for the verification process:

verification.status$.subscribe((status) => {
console.log("New status:", status);
});

This will log any changes in the verification status to the console.

Full Configuration Example

Here's a complete example of how to configure and use the BeL2 SDK with the Elastos Smart Chain:

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

async function configureAndUseSDK() {
// Set up provider and signer
const provider = new ethers.JsonRpcProvider("https://api2.elastos.net/esc");
const signer = new ethers.Wallet("YOUR_WALLET_ACCOUNT_PRIVATE_KEY", provider);

// Create a verification instance
const txId = "YOUR_BITCOIN_TRANSACTION_ID";
const chainId = 20; // Elastos Smart Chain

const verification = await ZKP.EthersV6.TransactionVerification.create(
txId,
chainId
);

// Subscribe to status updates
verification.status$.subscribe((status) => {
console.log("New status:", status);
});

// Submit a 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);
}
}
}

configureAndUseSDK();

Next Steps

Now that you have configured the BeL2 SDK, you're ready to start submitting verification requests and checking their status. Refer to the Submit Verification and Check Verification Status guides for more information on how to use these features.

Remember to handle errors appropriately and implement proper security measures when working with blockchain transactions and sensitive data.

If you encounter any issues during the configuration process, please refer to the Troubleshooting section or reach out to our support team.