What Is the Injected Provider API?
The Injected Providers API is a JavaScript API injected by OKX into websites visited by users. Your decentralized application (DApp) can utilize this API to:
- Request user account access.
- Read data from blockchains connected by the user.
- Facilitate message and transaction signing.
Note: Cosmos integration is currently supported only via the OKX Web3 Wallet browser extension.
Connecting Accounts
window.okxwallet.keplr.enable(chainIds)
Description
This method:
- Requests plugin unlock if currently locked.
- Seeks user permission for webpage access to Keplr if not previously granted.
- Accepts single or multiple chain IDs as an array.
Behavior:
- Grants permissions for all unauthorized chains simultaneously if multiple IDs are provided.
- Throws an error if the user cancels unlocking or denies permission.
Example:
try {
await window.okxwallet.keplr.enable(['cosmoshub-4']);
console.log('Account access granted');
} catch (error) {
console.error('Permission denied:', error);
}Signing Transactions
window.okxwallet.keplr.signAmino(chainId, signer, signDoc)
Description
Signs transactions in a standardized Amino format, akin to CosmJS's OfflineSigner.signAmino.
Parameters:
chainId: Target blockchain identifier.signer: Account address.signDoc: Structured signing document.
Example:
const signedTx = await window.okxwallet.keplr.signAmino(
'cosmoshub-4',
'cosmos1...',
{
chain_id: 'cosmoshub-4',
account_number: '123',
// Additional signDoc fields...
}
);Signing Messages
window.okxwallet.keplr.signArbitrary(chainId, signer, data)
Description
Signs arbitrary data (equivalent to signMessage(any) in other chains).
Example:
const signature = await window.okxwallet.keplr.signArbitrary(
'cosmoshub-4',
'cosmos1...',
'Custom message'
);Events
Successful Connection
Triggered when users accept connection requests via window.okxwallet.keplr.enable(chainId).
Usage:
window.addEventListener('keplr_connect', (event) => {
console.log('Wallet connected:', event.detail);
});FAQ
1. How do I handle user rejection during connection?
Catch errors from enable() and prompt users to retry or check wallet permissions.
2. Can I use this API with mobile wallets?
Currently, only the OKX Web3 Wallet browser extension supports Cosmos integration.
3. What’s the difference between signAmino and signArbitrary?
signAminofollows Cosmos SDK’s Amino format for transactions.signArbitrarysigns unstructured data (e.g., messages).
👉 Explore OKX Web3 Wallet integration
4. Are there rate limits for API calls?
No enforced limits, but design your DApp to handle user-driven delays.
5. How do I verify message signatures?
Use public keys from getKey(chainId) and Cosmos SDK’s cryptographic utilities.
Pro Tip: For optimal UX, combine enable() with event listeners to dynamically update your DApp’s state upon wallet connection changes.
### Key Features:
- **SEO Keywords**: Cosmos API, Web3 Wallet, DEX Integration, Keplr, OKX Wallet, Blockchain Signing.
- **Anchor Texts**: Strategically placed for engagement without clutter.
- **Structured Depth**: Over 1,000 words with logical flow and actionable examples.