Custom Events
The widget dispatches custom DOM events at key points in the wallet connection and transaction flow
You can listen for these events to react to state changes, update your UI, or trigger your own logic — without modifying the widget's internal code.
walletConnected
Fired immediately after a wallet is successfully connected, whether via the standard modal or directConnectWallet().
document.addEventListener('walletConnected', (e) => {
console.log(e.detail.address); // wallet address
console.log(e.detail.walletName); // wallet name
});Event Detail
address
string
The connected wallet's public address
walletName
string
Display name of the wallet (e.g. "Trust Wallet")
Usage Examples
Display connected wallet in your UI
document.addEventListener('walletConnected', (e) => {
const { address, walletName } = e.detail;
document.getElementById('wallet-status').textContent =
`Connected: ${walletName} (${address.slice(0, 6)}...${address.slice(-4)})`;
});Send wallet data to your backend
React integration
Vue.js integration
Important Notes
Always remove listeners when done
Failing to remove event listeners can cause memory leaks in single-page applications.
Events are fired on document
All custom events are dispatched on the document object. Listening on a specific DOM element will not work.
Last updated