Skip to main content

API Reference

This API reference provides detailed information about the main classes, methods, and types in the BeL2 SDK.

ZKP Module​

The ZKP module is the main entry point for the SDK's functionality.

ZKP.EthersV6.TransactionVerification​

create(txId: string, chainId: number | bigint, provider?: Web3Provider): Promise<TransactionVerification>​

Creates a new TransactionVerification instance.

  • txId: The Bitcoin transaction ID to verify.
  • chainId: The EVM chain ID where the verification will be performed.
  • provider (optional): A custom Web3Provider. If not provided, a default provider will be used.

Returns: A Promise that resolves to a TransactionVerification instance.

submitVerificationRequest(signer: JsonRpcSigner | Wallet, scriptHex?: string, waitForResult = false): Promise<string>​

Submits a verification request for the Bitcoin transaction.

  • signer: The EVM signer to use for the transaction.
  • scriptHex (optional): A script hex to ensure that a script output matches transaction outputs.
  • waitForResult (optional): Whether to wait for the result of the verification request.

Returns: A Promise that resolves to the transaction hash of the verification request.

checkStatus(): Promise<void>​

Checks the current status of the verification request and updates the status$ observable.

Returns: A Promise that resolves when the status check is complete.

isSubmitted(): boolean​

Checks if a verification request has already been submitted for this transaction.

Returns: true if a request has been submitted, false otherwise.

status$: BehaviorSubject<TransactionVerificationStatus>​

An observable that emits the current status of the verification request.

TransactionVerificationStatus​

An enum representing the possible states of a verification request:

  • 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

Utility Types​

JsonRpcSigner​

Represents a JSON-RPC signer from the Ethers.js library.

Web3Provider​

Represents a Web3 provider from the Ethers.js library.

Error Handling​

The SDK uses standard JavaScript error handling. Most asynchronous methods can throw errors, which should be caught and handled appropriately in your application.

Example:

try {
const response = await verification.submitVerificationRequest(signer);
console.log("Verification request submitted:", response);
} catch (error) {
console.error("Error submitting verification request:", error);
// Handle the error appropriately
}

Best Practices​

  1. Always check if a verification request has already been submitted using isSubmitted() before calling submitVerificationRequest().
  2. Use the status$ observable to react to status changes in real-time.
  3. Implement proper error handling for all SDK method calls.
  4. When using the SDK in a browser environment, ensure that the user has connected their wallet before attempting to submit a verification request.

For more detailed examples and use cases, refer to the other sections of the documentation:

If you encounter any issues or have questions about using the API, please consult the Troubleshooting guide or reach out to our support team.