What is the Injected Provider API?
The Injected Provider API is a JavaScript interface that enables seamless communication between decentralized applications (DApps) and cryptocurrency wallets. This API allows DApps to:
- Request user account access
- Read blockchain data
- Facilitate message signing
- Process transactions
Account Connection Process
Primary Connection Method
window.okxwallet.solana.connect()
Key Features:
- Returns a
Promise
object - Resolves when user approves connection
- Rejects when user denies request
- Triggers connection events upon success
Connection Status Indicators:
- Public key visibility for connected accounts
isConnected
boolean flag for easy status checks
Transaction Signing Methods
1. Sign & Send Transaction
window.okxwallet.solana.signAndSendTransaction(transaction)
2. Sign Without Sending
window.okxwallet.solana.signTransaction(transaction)
3. Batch Transaction Signing
provider.signAllTransactions(transactions)
Post-Signature Options:
- Submit signed transactions via
@solana/web3.js
usingsendRawTransaction
Message Signing Capabilities
window.okxwallet.solana.signMessage(args)
Requirements:
- Accepts hex or UTF-8 encoded strings as Uint8Array
- No network fees required
- Ideal for address ownership verification
Event Handling System
1. Connection Events
- Triggered upon successful wallet connection
- Handles user authorization responses
2. Disconnection Events
- Initiated by either application or wallet
- Follows same pattern as connection process
3. Account Change Events
- Emits
accountChanged
when users switch accounts - Maintains connection if new account is whitelisted
👉 Explore advanced wallet integration techniques
Best Practices for Developers
Error Handling
- Implement comprehensive error responses
- Account for all possible rejection scenarios
User Experience
- Clear authorization prompts
- Immediate feedback on transaction status
Security Considerations
- Never store private keys
- Validate all signed messages
FAQ Section
Q1: What's the difference between signTransaction and signAndSendTransaction?
A: signTransaction
only creates signatures, while signAndSendTransaction
both signs and broadcasts the transaction to the network.
Q2: How do I handle multiple wallet connections?
A: The API automatically manages account changes through events - simply listen for accountChanged
events.
Q3: What encoding formats does signMessage support?
A: The method accepts both hex and UTF-8 encoded strings formatted as Uint8Array.
Q4: Can I batch transaction requests?
A: Yes, use signAllTransactions
to process multiple transactions simultaneously.
👉 Learn more about Solana-compatible chain integration
Implementation Examples
Basic Connection Template
try {
const response = await window.okxwallet.solana.connect();
console.log('Connected public key:', response.publicKey.toString());
} catch (error) {
console.error('Connection error:', error);
}
Transaction Processing Sample
const transaction = new Transaction().add(
SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: recipient,
lamports: amount,
})
);
const signature = await window.okxwallet.solana.signAndSendTransaction(transaction);