Event Reference
OxGasAuth and OxGasClient implement an event emitter. You can listen for changes in connection state, transaction signing, and errors.
Subscribe to an event. Returns a function that you can call to unsubscribe.
const unsubscribe = client.on('stateChange', (state) => { console.log('New state:', state);});
// Later:unsubscribe();once()
Section titled “once()”Subscribe to an event, but automatically unsubscribe after the first time it fires.
client.once('connected', (wallet) => { console.log('Logged in for the first time this session:', wallet.address);});Remove a specific listener function.
function handleDisconnect() { console.log('Disconnected');}
client.on('disconnected', handleDisconnect);client.off('disconnected', handleDisconnect);removeAllListeners()
Section titled “removeAllListeners()”Remove all listeners for a specific event, or for all events if no name is provided.
// Remove all 'error' listenersclient.removeAllListeners('error');
// Remove everythingclient.removeAllListeners();Available Events
Section titled “Available Events”stateChange
Section titled “stateChange”Fired whenever the authentication state transitions.
- Payload:
"disconnected" | "connecting" | "connected"
client.on('stateChange', (state) => { // Update UI loading spinners, etc.});connected
Section titled “connected”Fired when the user successfully logs in and wallet info is available.
- Payload:
WalletInfoobject ({ address, email })
client.on('connected', (wallet) => { console.log('Welcome,', wallet.email);});disconnected
Section titled “disconnected”Fired when the user logs out, the session is destroyed, or an authentication error forces a disconnect.
- Payload: None
client.on('disconnected', () => { // Clear user data from your app's state});signatureComplete
Section titled “signatureComplete”Fired when a signMessage or signTransaction request successfully completes.
- Payload:
{ type: 'message' | 'transaction', hash: string }
client.on('signatureComplete', (info) => { console.log(`Just signed a ${info.type} with hash ${info.hash}`);});Fired when a widget-level error occurs that isn’t caught by a specific promise. For example, if the widget unexpectedly closes while idle.
- Payload:
WidgetError
client.on('error', (err) => { console.error('Widget background error:', err.message);});