What is the Injected Provider API (Testnet)?
The OKX Injected Providers API (Testnet) enables seamless interaction between decentralized applications (DApps) and Bitcoin-compatible testnet blockchains. This JavaScript-based API allows DApps to:
- Request user account information
- Read blockchain data
- Facilitate message and transaction signing
- Connect with extension wallets
๐ Explore Bitcoin Testnet Wallet Integration
Core Functions
Connect Wallet
okxwallet.bitcoinTestnet.connect()Parameters: None
Returns:
Promise<object>containing:address(string): Current account addresspublicKey(string): Current account public key
Example Use Case:
async function connectWallet() {
const { address, publicKey } = await okxwallet.bitcoinTestnet.connect();
console.log(`Connected: ${address}`);
}Sign Messages
okxwallet.bitcoinTestnet.signMessage(signStr[, type])Parameters:
signStr(string): Data to signtype(optional string): "ecdsa" | "bip322-simple" (default: "ecdsa")
Returns: Promise<string> (signature result)
Best Practices:
- Always verify message contents before signing
- Use "bip322-simple" for advanced Bitcoin message formats
PSBT Signing Operations
Single PSBT Signing
okxwallet.bitcoinTestnet.signPsbt(psbtHex[, options])Parameters:
psbtHex(string): Hexadecimal PSBT representationoptions(optional object):autoFinalized(boolean): Auto-finalize after signing (default: true)toSignInputs(array): Specify inputs to signdisableTweakSigner(boolean): Sign with original private key
Returns: Promise<string> (signed PSBT hex)
Batch PSBT Signing
okxwallet.bitcoinTestnet.signPsbts(psbtHexs[, options])Parameters:
psbtHexs(string[]): Multiple PSBT hex stringsoptions(object[]): Per-PSBT signing options
Returns: Promise<string[]> (signed PSBT hex strings)
๐ Master PSBT Signing Techniques
FAQ Section
Why use the Testnet Provider API?
Testnet allows developers to experiment without risking real funds while maintaining full Bitcoin protocol compatibility.
How secure is message signing?
All signing operations occur locally in the wallet extension, with explicit user confirmation required for each action.
What's the difference between ECDSA and BIP322 signing?
ECDSA is standard elliptic curve signing, while BIP322-Simple provides improved Bitcoin message format standardization.
Can I use this API with hardware wallets?
Yes, the API is compatible with most hardware wallets when used through supported browser extensions.
How do I handle PSBTs with Taproot inputs?
Ensure each Taproot input includes its corresponding public key in the PSBT construction phase.
What happens if autoFinalized is disabled?
You'll need to manually finalize the PSBT after signing to complete the transaction preparation process.