What is the Injected Provider API?
The Injected Provider API is a JavaScript interface that allows decentralized applications (DApps) to interact with users’ TronLink browser extension wallets. This powerful API enables your DApp to:
- Request access to user accounts
- Read data from connected blockchains
- Facilitate message and transaction signing
- Execute smart contract interactions
👉 Explore advanced wallet integration techniques
Connecting User Accounts
Authorization Request Method
javascript
window.okxwallet.tronLink.request(args)
Key Features
- Initiates secure connection between DApp and wallet
- Required before performing any transactions or signatures
- User must explicitly approve the connection
Status Codes
Code | Description | Message |
---|---|---|
200 | Pre-approved site | The site is already in the whitelist |
200 | User approved | User allowed the request |
4000 | Pending request | Authorization requests being processed |
4001 | User rejected | User rejected the request |
TRX Transfer Process
- Create transaction – Prepare unsigned transfer
- Sign transaction – User approval via TronLink
- Broadcast transaction – Submit to TRON network
👉 See live code implementation
Transaction Signing
Signing Method
javascript
okxwallet.tronLink.tronWeb.trx.sign(transaction, privateKey)
Step 1: Creating Transactions
sendTRX Parameters
Parameter | Description | Type |
---|---|---|
to | Recipient address | hexString |
amount | TRX quantity | integer |
from | Sender address (optional) | hexString |
options | Permission ID | integer |
Step 2: Signing Transactions
Security Note: Never expose private keys in web applications
Sign Parameters
Parameter | Description | Type |
---|---|---|
transaction | Transaction object | JSON |
privateKey | Signing key (optional) | String |
Step 3: Broadcasting Transactions
sendRawTransaction Parameters
Parameter | Description | Type |
---|---|---|
signedTransaction | Signed transaction object | JSON |
Message Signing
Signature Method
javascript
window.okxwallet.tronLink.tronWeb.trx.sign(message)
Version Compatibility
- Pre-2.80.0: Always converts to hexadecimal
- 2.80.0+: Maintains original format (hex or string)
Parameters
Parameter | Description | Type |
---|---|---|
message | String (hex or plaintext) | String |
Return Values
- Successful signing returns hexadecimal string
- Errors return specific rejection messages
Signature Verification
Verification Method
javascript
window.okxwallet.tronLink.tronWeb.trx.verifyMessage(hexMsg, signedMsg[, address])
Parameters
Parameter | Description | Type |
---|---|---|
hexMsg | Hexadecimal message | String |
signedMsg | Signature result | String |
address | Verifying address (optional) | String |
Return Value
Promise resolving to boolean (true/false)
Wallet Events
Connection Events
- Connect: User approves connection or wallet connects
- Disconnect: User rejects or disconnects wallet
- Account Change: Login, switch, or lock events
Event Handling Examples
“`javascript
window.okxwallet.tronLink.on(‘connect’, (data) => {
console.log(‘Wallet connected:’, data)
})
window.okxwallet.tronLink.on(‘disconnect’, () => {
console.log(‘Wallet disconnected’)
})
“`
Frequently Asked Questions
How secure is the Injected Provider API?
The API maintains high security standards by:
– Requiring explicit user consent for all actions
– Never exposing private keys to DApps
– Implementing strict permission systems
What browsers support TronLink integration?
TronLink works on all Chromium-based browsers (Chrome, Brave, Edge) and Firefox. Mobile support varies by wallet implementation.
Can I use this API with other TRON wallets?
While designed for TronLink, the API follows common standards that may work with compatible wallets. Always test alternative implementations.
How do I handle failed transactions?
Implement comprehensive error handling:
javascript
try {
const result = await window.okxwallet.tronLink.request(...)
} catch (error) {
console.error('Transaction failed:', error)
}
What’s the difference between sign() and verifyMessage()?
sign()
creates cryptographic signaturesverifyMessage()
validates existing signatures- Both are essential for secure authentication flows
How often should I check connection status?
We recommend:
– Checking on initial page load
– Monitoring disconnect events
– Verifying before critical transactions
For developers building on TRON, understanding these wallet integration techniques is crucial for creating seamless Web3 experiences. The TronLink Provider API offers powerful capabilities while maintaining strong security protections for end users.