Wallet account addresses are used in various scenarios, including as identifiers and for signing transactions.
It is recommended to provide a button here that allows users to connect the OKX Web3 Wallet Tron to the DApp.
In the example project code below, the JavaScript code accesses the user's account address when the user clicks the connect button, and the HTML code displays the button and the current account address:
<button class="connectTronButton">Connect Tron</button>
const connectTronButton = document.querySelector('.connectTronButton');
connectTronButton.addEventListener('click', () => {
//Will Start the OKX extension
window.okxwallet.tronLink.request({ method: 'tron_requestAccounts'})
});
You can also listen to the emitted events to get updates:
window.addEventListener('message', function (e) {
if (e.data.message && e.data.message.action === "accountsChanged") {
// handler logic
console.log('got accountsChanged event', e.data, e.data.message.address)
}
})
The OKX provider will emit this event whenever the return value of the tron_requestAccounts
RPC changes.