Skip to main content

Interacting with a Browser Wallet that Not Directly Supporting OP_NET

This guide outlines strategies for interacting with extensions that do not natively support OP_NET. It includes methods for indirect signatures, creating custom signers, and adapting existing APIs for different browser wallet extensions.


Example with xVerse

For extensions that don't directly support OP_NET, like xVerse, developers can adapt their APIs for compatibility. Below is an example of integrating xVerse into your application.

interface XverseBitcoinProvider {
request: (method: string, params: string | null) => Promise<XverseResponse>;
// ... other fields
}

interface XverseProviders {
BitcoinProvider: XverseBitcoinProvider;
}

interface CustomWindow {
XverseProviders?: XverseProviders;
}

interface XverseAddress {
address: string;
// ... other fields
}

interface XverseBalanceResult {
total: number;
// ... other fields
}

interface XverseResult extends XverseBalanceResult {
addresses: XverseAddress[];
id: string;
walletType: string;
}

interface XverseResponse {
id: string;
jsonrpc: string;
result: XverseResult;
}

const _window: CustomWindow = window as CustomWindow;

const xverse: XverseBitcoinProvider | undefined =
_window.XverseProviders?.BitcoinProvider;

if (!xverse) {
throw new Error("Xverse Wallet not found");
}

const balanceRequest: XverseResponse = await xverse.request("getBalance", null);
const finalBalance: XverseBalanceResult = balanceRequest.result;
const balance = BigInt(Number(finalBalance.total)).toString();

console.log("Wallet Balance:", balance);

Indirect Signatures

COMING SOON

A future update will include support for UnisatProvider in @btc-vision/transaction for managing indirect signatures. Stay tuned for updates.


Creating Custom Signers

When extensions lack direct OP_NET support, developers can create custom signers by extending existing classes and adapting the API logic.

For Example:

import { UnisatSigner } from "@btc-vision/transaction";
import { useState } from "react";

const [signer, setSigner] = useState<UnisatSigner | null>(null);

const initSigner = async () => {
const signer = new UnisatSigner();
await signer.init();
setSigner(signer);
};

await initSigner();
console.log("Signer initialized:", signer);

Best Practices

  • Always ensure the browser extension is installed and initialized before attempting to interact with it.
  • Customize API methods for compatibility with different wallet providers to maintain seamless functionality.
  • Create or extend existing signer classes when dealing with unsupported extensions.

What’s Next?