Bitcoin-Compatible Chain SDK: Connect Your DApp or Mini Wallet

·

Integrating blockchain functionality into your decentralized application (DApp) or mini wallet has never been easier. With the latest updates to the OKXUniversalProvider SDK, developers can now seamlessly connect to a Bitcoin-compatible chain, manage user wallets, sign transactions, and interact with decentralized exchanges (DEXs) through a robust API framework. This guide walks you through the full integration process—from initialization to transaction execution—while ensuring compatibility, security, and optimal user experience.

Whether you're building on EVM networks or tapping into Bitcoin’s growing ecosystem via fractal or mainnet chains, this SDK offers modular tools for modern Web3 development.


Installation and Initialization

To begin integrating wallet connectivity into your DApp, ensure your environment supports version 6.92.0 or later of the OKX SDK. You can install it using npm:

npm install okx-sdk

Before enabling wallet interactions, initialize the provider with your app’s metadata:

OKXUniversalProvider.init({
  dappMetaData: {
    name: "Your DApp Name",
    icon: "https://yourdomain.com/icon.png" // 180x180px PNG recommended
  }
});

👉 Discover how to set up wallet integration in under 5 minutes

Parameters

Returns


Connecting to a Wallet

Establish a secure session between your DApp and the user’s wallet to access addresses and transaction signing capabilities.

okxUniversalProvider.connect({
  namespaces: {
    btc: {
      chains: ["btc:mainnet", "fractal:mainnet"],
      defaultChain: "btc:mainnet"
    }
  },
  sessionConfig: {
    redirect: "tg://resolve" // For Telegram Mini Apps
  }
});

Request Parameters

Returns (Promise)

On success, returns an object with:


Check Wallet Connection Status

Verify whether a wallet is currently connected before proceeding with sensitive operations.

const isConnected = okxUniversalProvider.isConnected();

Returns

This simple check helps prevent errors during transaction requests and improves UX by guiding users to connect first.


Send Signatures and Transactions

After connection, create an instance of OKXBtcProvider to interact directly with Bitcoin-based chains:

const okxBtcProvider = new OKXBtcProvider(okxUniversalProvider);

Get Account Information

Retrieve wallet address and public key for a specific chain.

const account = await okxBtcProvider.getAccount("btc:mainnet");

Parameters

Returns


Sign Messages

Securely sign arbitrary messages for authentication or identity verification.

const signature = await okxBtcProvider.signMessage("btc:mainnet", "Hello World", "ecdsa");

Parameters

Returns


Sending Bitcoin Transactions

Use flexible methods to send BTC with customizable fees and metadata.

Method 1: Standard Send

const result = await okxBtcProvider.send("btc:mainnet", {
  from: "bc1q...",
  to: "bc1p...",
  value: "0.001",
  satBytes: "10",
  memo: "Payment for service",
  memoPos: 1
});

Parameters

Returns


Method 2: Simplified Bitcoin Send

For basic transfers:

const txHash = await okxBtcProvider.sendBitcoin("btc:mainnet", "bc1p...", 100000, { feeRate: 15 });

Parameters

Returns


Signing PSBTs (Partially Signed Bitcoin Transactions)

Enable advanced transaction workflows with full control over inputs and outputs.

const signedPsbt = await okxBtcProvider.signPsbt("btc:mainnet", "psbt_hex_string", {
  autoFinalized: true,
  toSignInputs: [{
    index: 0,
    address: "bc1q...",
    publicKey: "03..."
  }]
});

Parameters

Returns


Sign Multiple PSBTs at Once

Batch-sign several transactions efficiently:

const signedHexes = await okxBtcProvider.signMultiplePsbt("btc:mainnet", ["psbt1...", "psbt2..."], options);

Ideal for DEX aggregators or multi-swap platforms.

👉 Learn how top DApps streamline transaction signing


Sign and Broadcast PSBT in One Step

Available in App version 6.93.0+, this method signs and pushes the transaction directly to the network.

const result = await okxBtcProvider.signAndPushPsbt("btc:mainnet", "psbt_hex", options);

Returns

Perfect for non-custodial trading interfaces requiring speed and reliability.


Disconnect Wallet

Terminate the active session securely:

okxUniversalProvider.disconnect();

Always disconnect before attempting to switch accounts or reconnect.


Event Handling

The SDK emits real-time events such as:

Subscribe using standard event listeners to update UI dynamically.


Error Codes and Troubleshooting

Handle exceptions gracefully using standardized error codes:

Common exceptions include:

Catch these in promises to display meaningful feedback.


FAQ Section

Q: What Bitcoin-compatible chains are supported?
A: Currently supports btc:mainnet and fractal:mainnet. Additional chains may be added via optional namespaces.

Q: Can I use SVG icons for my DApp?
A: No. Only PNG or ICO formats are accepted. Use a 180×180px PNG for optimal display.

Q: Is it possible to reconnect automatically after disconnection?
A: Not automatically. You must prompt the user to reconnect manually for security reasons.

Q: How do I embed data into transactions?
A: Use the memo and memoPos parameters in the send() method to include OP_RETURN content.

Q: What is the difference between sendBitcoin() and send()?
A: sendBitcoin() is a simplified method for basic transfers. send() offers more options like memos and custom fee rates.

Q: Can I sign Taproot transactions?
A: Yes. Use the signPsbt method with appropriate input configurations. Set disableTweakSigner if needed.


Core Keywords

Bitcoin-compatible chain, wallet integration, DApp SDK, PSBT signing, transaction broadcasting, connect wallet, OKX API, decentralized exchange integration

👉 Start integrating today — no setup fees, full documentation included