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-sdkBefore 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
dappMetaData— Object containing:name(string): Display name of your application.icon(string): Direct URL to a PNG or ICO file. SVG icons are not supported. For best results, use a 180×180 pixel PNG.
Returns
OKXUniversalProvider: An instance used for all subsequent wallet operations.
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
namespaces— Required chain specifications:- Keyed by
'btc'for Bitcoin-compatible chains. - Includes
chainsarray and optionaldefaultChain.
- Keyed by
optionalNamespaces— Fallback chains; connection proceeds even if unsupported.sessionConfig.redirect— Redirect URI post-connection (e.g., Telegram deep links).
Returns (Promise)
On success, returns an object with:
topic: Unique session identifier.chains: Active chain IDs.accounts: Connected wallet addresses.methods: Supported signing methods.dappInfo: Your app’s registered name and icon.redirect: Post-connect navigation path.
Check Wallet Connection Status
Verify whether a wallet is currently connected before proceeding with sensitive operations.
const isConnected = okxUniversalProvider.isConnected();Returns
boolean:trueif connected,falseotherwise.
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
chainId: e.g.,"btc:mainnet"or"fractal:mainnet"
Returns
address: Wallet’s public address.publicKey: Associated public key for verification.
Sign Messages
Securely sign arbitrary messages for authentication or identity verification.
const signature = await okxBtcProvider.signMessage("btc:mainnet", "Hello World", "ecdsa");Parameters
chain: Target chain ID.message: String to sign.type: Optional;'ecdsa'(default) or'bip322-simple'.
Returns
- Signed message as a hexadecimal string.
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
from,to,value: Required fields.satBytes: Custom sat/vB fee rate.memo&memoPos: Optional OP_RETURN data embedding.
Returns
txHash: Transaction ID on the blockchain.
Method 2: Simplified Bitcoin Send
For basic transfers:
const txHash = await okxBtcProvider.sendBitcoin("btc:mainnet", "bc1p...", 100000, { feeRate: 15 });Parameters
toAddress: Recipient address.satoshis: Amount in satoshis.options.feeRate: Optional custom fee.
Returns
- Transaction hash as string.
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
psbtHex: Hex-encoded PSBT.options.toSignInputs: Specify which inputs to sign with corresponding keys.
Returns
- Hex string of the signed PSBT.
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
txhash: Broadcasted transaction ID.signature: Final signed PSBT hex.
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:
"connect""disconnect""chainChanged""accountsChanged"
Subscribe using standard event listeners to update UI dynamically.
Error Codes and Troubleshooting
Handle exceptions gracefully using standardized error codes:
Common exceptions include:
OKX_CONNECT_ERROR_CODES.USER_REJECTS_ERROR: User declined connection request.OKX_CONNECT_ERROR_CODES.CHAIN_NOT_SUPPORTED: Chain not available in wallet.OKX_CONNECT_ERROR_CODES.NOT_CONNECTED_ERROR: Attempting action without connection.OKX_CONNECT_ERROR_CODES.METHOD_NOT_SUPPORTED: Unsupported operation on current chain.OKX_CONNECT_ERROR_CODES.CONNECTION_ERROR: Network or handshake failure.
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