The OKX Injected Provider API (Testnet) is a powerful development tool designed for seamless integration between decentralized applications (DApps) and the Bitcoin-compatible testnet chain via the OKX Wallet extension. Built on an embedded JavaScript model, this API enables developers to securely interact with user wallets—requesting account details, reading blockchain data, and facilitating transaction and message signing—all within a trusted environment.
Whether you're building a decentralized exchange (DEX), a blockchain explorer, or a Bitcoin-based smart contract platform, understanding how to use the OKX Provider API effectively is essential for delivering a smooth and secure user experience on testnet environments.
Understanding the Injected Provider API (Testnet)
The OKX Injected Provider API (Testnet) operates by injecting a JavaScript object (okxwallet) directly into the browser’s web page context when the OKX Wallet extension is installed. This allows DApps to communicate with the wallet without requiring users to expose their private keys.
Developers can use this API to:
- Request user wallet connection
- Retrieve public account information
- Sign messages and transactions securely
All interactions occur only after explicit user approval, ensuring privacy and security are maintained at every step.
👉 Discover how to integrate wallet connectivity effortlessly into your DApp
Core API Methods
Below are the primary methods available in the okxwallet.bitcoinTestnet namespace, each designed to support secure, user-approved interactions with the Bitcoin testnet.
connect()
Description
Establishes a connection between your DApp and the user's OKX Wallet.
Parameters
None
Return Value
A Promise that resolves to an object containing:
address(string): The current account’s Bitcoin testnet addresspublicKey(string): The corresponding public key
Example Usage
try {
const result = await okxwallet.bitcoinTestnet.connect();
console.log("Connected Address:", result.address);
console.log("Public Key:", result.publicKey);
} catch (error) {
console.error("Connection failed:", error);
}This method triggers a pop-up in the OKX Wallet extension where users must confirm the connection—ensuring full control remains in their hands.
signMessage(signStr[, type])
Description
Allows the user to sign a message using their private key, useful for authentication or identity verification.
Parameters
signStr(string): The message to be signedtype(optional string): Signature algorithm —"ecdsa"or"bip322-simple"(default:"ecdsa")
Return Value
A Promise that resolves to a signed string (hex-encoded).
Example Usage
const signature = await okxwallet.bitcoinTestnet.signMessage("Hello Testnet", "ecdsa");
console.log("Signature:", signature);This function is commonly used in login flows where users prove ownership of an address without transferring funds.
signPsbt(psbtHex[, options])
Description
Signs a Partially Signed Bitcoin Transaction (PSBT), commonly used in multi-signature or complex transaction setups.
Parameters
psbtHex(string): Hexadecimal representation of the PSBToptions(object, optional):autoFinalized(boolean): Automatically finalize PSBT after signing (default:true)toSignInputs(array): Specifies which inputs to sign using eitheraddressorpublicKeysighashTypes(number[]): Optional array of sighash typesdisableTweakSigner(boolean): For Taproot addresses, disables tweak signing and uses original private key
Note: When creating a PSBT involving Taproot inputs, ensure each input includes its public key.
Return Value
A Promise resolving to the signed PSBT as a hex string.
👉 Learn how to build secure Bitcoin transaction flows in minutes
signPsbts(psbtHexs[, options])
Description
Signs multiple PSBTs in a single call, ideal for batch processing or multi-transaction DApps.
Parameters
psbtHexs(string[]): Array of PSBT hex stringsoptions(array of objects): Same structure assignPsbt, applied per PSBT
Return Value
A Promise resolving to an array of signed PSBT hex strings.
Use Case Example
A DEX frontend might generate separate PSBTs for swap, fee, and liquidity operations—then sign them all at once with user consent.
Best Practices for Secure Integration
To ensure your DApp delivers both performance and security:
- Always verify returned addresses match expected formats
- Use BIP322 signatures for more robust message authentication
- Handle errors gracefully—network issues or user rejection should not crash your app
- Never store private keys or signatures on your server
- Prompt users clearly about what they’re signing
Security isn’t just technical—it’s also about transparency. Inform users why you need access and what actions you’ll perform on their behalf.
Frequently Asked Questions (FAQ)
What is the difference between signPsbt and signPsbts?
signPsbt signs a single transaction, while signPsbts allows batch signing of multiple PSBTs. Use the latter when efficiency matters—like processing several swaps or withdrawals together.
Can I use this API on mainnet?
No. This documentation covers only the testnet version of the OKX Injected Provider API. Mainnet functionality may differ slightly and requires additional compliance checks. Always test thoroughly before going live.
Is user approval required for every action?
Yes. Every connection request, message sign, or transaction sign triggers a user confirmation dialog in the OKX Wallet extension. This ensures no unauthorized actions occur.
Why do I need to include public keys for Taproot inputs?
Taproot scripts require knowledge of the public key to construct valid signatures. Without it, the wallet cannot determine how to unlock the UTXO, leading to signing failure.
How does BIP322 signing improve security?
BIP322 supports signing arbitrary messages using Bitcoin’s script system, making it more versatile than ECDSA. It allows for better compatibility with future script upgrades and provides stronger cryptographic guarantees.
Does this work with other wallets?
Currently, this API is specific to OKX Wallet. While similar in concept to other injected providers (like MetaMask), syntax and capabilities may vary across wallets.
Final Thoughts
The OKX Injected Provider API (Testnet) empowers developers to build next-generation Bitcoin-compatible DApps with robust wallet integration. By leveraging standardized methods like connect, signMessage, and PSBT handling, you can create secure, intuitive experiences that align with modern web3 expectations.
Whether you're prototyping a new DEX interface or testing atomic swaps on Bitcoin testnet, this API offers the tools you need—all while keeping users in full control of their assets.
👉 Start integrating secure wallet functionality into your project today