What Is the Injected Provider API?
The OKX Injected Provider API is a powerful JavaScript interface that enables seamless interaction between decentralized applications (DApps) and the OKX Wallet browser extension. This API allows developers to:
- Request user account access
- Read blockchain data from connected networks
- Facilitate message and transaction signing
- Manage wallet connections and events
Key Features of WAX API Integration
Scatter Protocol Compatibility
OKX Wallet's WAX API maintains full compatibility with the Scatter protocol, offering developers familiar functionality with these enhanced capabilities:
👉 Discover advanced wallet integration techniques
Wallet Connection Workflow
1. Establishing Wallet Connection
// Example connection code using Scatter protocol
if (window.okxwallet) {
const result = await window.okxwallet.connect();
console.log('Connected:', result);
}2. Connection Status Verification
const isConnected = await window.okxwallet.isConnected();
console.log('Wallet status:', isConnected ? 'Connected' : 'Disconnected');3. Retrieving Wallet Information
const walletInfo = await window.okxwallet.getWalletInfo();
console.log('Current wallet:', walletInfo || 'No active connection');Transaction Signing Process
Using eosjs for Transaction Management
const { Api, JsonRpc } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig');
// Initialize with OKX provider
const signatureProvider = new JsSignatureProvider([window.okxwallet]);
const rpc = new JsonRpc('https://wax.greymass.com');
const api = new Api({ rpc, signatureProvider });Event Listening System
Supported Events and Handlers
| Event | Trigger Condition | Handler Example |
|---|---|---|
connect | Wallet connection established | wallet.on('connect', (account) => {...}) |
disconnect | User disconnects wallet | wallet.on('disconnect', () => {...}) |
accountChanged | Active account switched | wallet.on('accountChanged', (newAccount) => {...}) |
👉 Explore complete event handling examples
Frequently Asked Questions
Q: How does OKX's implementation differ from standard Scatter?
A: While maintaining protocol compatibility, OKX adds enhanced security layers and optimized performance for high-frequency DEX operations.
Q: Can I use this with non-WAX blockchains?
A: The current implementation specializes in WAX blockchain operations, though similar principles apply to other EOSIO-based chains.
Q: What error handling should I implement?
A: Always include:
- Connection timeout checks
- Permission request fallbacks
- Transaction status verification
Q: Is there rate limiting?
A: Standard web3 rate limits apply. Implement exponential backoff for retries during network congestion.
Best Practices for DEX Integration
- Progressive Connection
Request minimal permissions initially, expanding as needed - State Management
Always verify connection status before transaction attempts - User Experience
Provide clear disconnection options and account switching UI Security
Implement:- End-to-end transaction validation
- Secure session handling
- Explicit user confirmation for sensitive actions
// Comprehensive example
async function fullIntegrationDemo() {
try {
if (!await window.okxwallet.isConnected()) {
await window.okxwallet.connect();
}
const currentAccount = await window.okxwallet.getWalletInfo();
console.log('Active account:', currentAccount);
// Transaction example
const transaction = {
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: currentAccount,
permission: 'active'
}],
data: {
from: currentAccount,
to: 'recipientaccount',
quantity: '1.0000 WAX',
memo: 'DEX integration test'
}
}]
};
const result = await api.transact(transaction, {
blocksBehind: 3,
expireSeconds: 30
});
console.log('Transaction confirmed:', result);
} catch (error) {
console.error('Integration error:', error);
}
}This comprehensive guide provides everything needed for robust WAX wallet integration through OKX's Provider API, combining technical precision with developer-friendly implementation strategies.