Skip to content

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();

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);

Remove all listeners for a specific event, or for all events if no name is provided.

// Remove all 'error' listeners
client.removeAllListeners('error');
// Remove everything
client.removeAllListeners();

Fired whenever the authentication state transitions.

  • Payload: "disconnected" | "connecting" | "connected"
client.on('stateChange', (state) => {
// Update UI loading spinners, etc.
});

Fired when the user successfully logs in and wallet info is available.

  • Payload: WalletInfo object ({ address, email })
client.on('connected', (wallet) => {
console.log('Welcome,', wallet.email);
});

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
});

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);
});