Our client was built with an event-first approach, and every module has its own set of events that you can listen to.

Types of events

There are two types of events that you can listen to:

  • State change events: These events are triggered when a module’s variable changes value. All variables are observable, and their corresponding events will always have the same name as the variable, followed by Changed.
  • Custom events: These events represent some specific action that has occurred in the module.

Listening to events

To listen to a module’s event, you need to call the on method on the module instance, passing the event name and a callback function as arguments.

You can just as easily remove the listener by calling the off method on the module instance, passing the event name and the same callback function as arguments.

const handleAuthSuccess = (user) => {
  console.log('User logged in', user)
}

dynamicClient.auth.on('authSuccess', handleAuthSuccess)

// When you no longer need to listen to the event

dynamicClient.auth.off('authSuccess', handleAuthSuccess)

You can add a one-off listener by calling the once method on the module instance instead of on.

List of events

You can find all the events that a module emits in the module’s documentation — for instance, take a look at the auth module’s documentation here.

However, for your convenience, below is a list of all the events that the client emits. Please refer to the module’s documentation for more information on each event.

Auth module

  • authInit: Emitted when the user initializes authentication, but before it either completes or fails.
  • authSuccess: Emitted when the user successfully logs in.
  • authFailed: Emitted when the user fails to log in.
  • loggedOut: Emitted when the user logs out.
  • userProfileUpdated: Emitted when the user’s profile is updated.
  • authenticatedUserChanged: State change event for the authenticatedUser variable.
  • tokenChanged: State change event for the token variable.

Email auth module

  • emailVerificationFinished: Emitted when the email verification process is completed.

SMS auth module

  • smsVerificationFinished: Emitted when the SMS verification process is completed.

Wallets module

  • messageSigned: Emitted when a message is signed.
  • walletAdded: Emitted when a wallet is added to the userWallets variable.
  • walletRemoved: Emitted when a wallet is removed from the userWallets variable.
  • primaryChanged: State change event for the primary variable.
  • userWalletsChanged: State change event for the userWallets variable.

Embedded wallets module

  • embeddedWalletCreated: Emitted when an embedded wallet is created.
  • hasWalletChanged: State change event for the hasWallet variable.

Networks module

  • evmChanged: State change event for the evm variable.
  • solanaChanged: State change event for the solana variable.

SDK module

  • error: Emitted when an error occurs.
  • loadedChanged: State change event for the loaded variable.

UI module

  • authFlowCancelled: Emitted when the user cancels the authentication flow (closes it before completing it).
  • authFlowClosed: Emitted when the authentication flow is closed, regardless of whether it was successfully completed or not.
  • authFlowOpened: Emitted when the authentication flow is opened.