The base package that provides access to the Dynamic Client, which can be extended with extension packages.

Functions

createClient

createClient(params: ClientProps): BaseClient

Returns an instance of a client object, which provides an interface to read state, trigger actions and listen to events of our SDK.

Types

ClientProps type

The parameters that are acceptable by the createClient method.

ParamTypeDescription
environmentIdstringThe ID of the environment of your dynamic application.
apiBaseUrlstring?Allows you to override the URL to which the SDK will make its API requests.
cssOverridesstring?Allows you to inject CSS into our UI modules (currently out of effect)
appNamestring?How you’d like your app to be named in our copies.
appLogoUrlstring?A URL of the logo of your app.

BaseClient type

The base type of a client.

Since clients can be extended (and thus have their types composed with those of the extensions), this is considered the most basic kind of client: the one that is returned from the createClient method.

Besides the .extend method which is inherited from the Extendable class, it is composed of properties which we call modules.

Note that all client modules implement an event emitter interface that allows you to call on, off and once to create and destroy event listeners.

For every property that is a state, there will always be an event name with the same name plus "Changed", which will be triggered when the property changes value. We will omit these from the docs below as they are implicit.

auth module

Provides access to authentication related properties and methods of the SDK.

PropertyTypeDescription
tokenstring | nullThe JWT of the currently logged in user.
authenticatedUserUserProfile | nullThe UserProfile object of the logged in user.
logout() => Promise<void>Allows you to log the current user out.
signInWithExternalJwt({ externalJwt: string; externalUserId: string }) => Promise<void>Logs the user in with a third-party JWT. This must be enabled in dashboard first.
verifyWithExternalJwt({ externalJwt: string; externalUserId: string }) => Promise<void>Links the dynamic user in with a third-party JWT. This must be enabled in dashboard first.
Event nameTypeDescription
authInit(data: AuthEventPayload) => voidEmitted when the user initializes authentication, but before it either completes or fails.
authSuccess(user: UserProfile) => voidEmitted when the user successfully logs in.
authFailed(data: AuthEventPayload, reason: 'user-cancelled' | { error: unknown }) => voidEmitted when the user fails to log in.
loggedOut(user: UserProfile | null) => voidEmitted when the user logs out.
userProfileUpdated(user: UserProfile) => voidEmitted when the user’s profile is updated.
authenticatedUserChanged(authenticatedUser: UserProfile | null) => voidState change event for the authenticatedUser variable.
tokenChanged(token: string | null) => voidState change event for the token variable.

auth.email submodule

Provides methods to send, re-send and verify OTPs to email.

PropertyTypeDescription
sendOTP(target: string) => Promise<void>Sends an OTP token to the target email.
resendOTP() => Promise<void>Sends another OTP token to the same email as the last call to sendOTP.
verifyOTP(token: string) => Promise<void>Receives an OTP token and logs the user in if it is valid.
Event nameTypeDescription
emailVerificationFinished(params: { isSuccess: boolean; destination: string }) => voidEmitted when the email verification process is completed.

auth.sms submodule

Provides methods to send, re-send and verify OTPs to phone numbers.

PropertyTypeDescription
sendOTP(target: PhoneData) => Promise<void>Sends an OTP token to the target PhoneData.
resendOTP() => Promise<void>Sends another OTP token to the same phone number as the last call to sendOTP.
verifyOTP(token: string) => Promise<void>Receives an OTP token and logs the user in if it is valid.
Event nameTypeDescription
smsVerificationFinished(params: { isSuccess: boolean; destination: PhoneData }) => voidEmitted when the SMS verification process is completed. See PhoneData

auth.social submodule

Provides a method to connect social accounts.

PropertyTypeDescription
connect(args: { provider: SocialProvider }) => Promise<void>Requests social connection to the provided SocialProvider.

networks module

Provides access to the current network configurations.

PropertyTypeDescription
evmGenericNetwork[]Which EVM networks are currently configured. See GenericNetwork
solanaGenericNetwork[]Which Solana networks are currently configured. See GenericNetwork
Event nameTypeDescription
evmChanged(evm: GenericNetwork[]) => voidState change event for the evm variable.
solanaChanged(solana: GenericNetwork[]) => voidState change event for the solana variable.

sdk module

Gives insight over the state of the SDK.

PropertyTypeDescription
loadedbooleanWhether the SDK has loaded and is ready to handle requests.
Event nameTypeDescription
error(error: Error | null) => voidEmitted when an error occurs.
loadedChanged(loaded: boolean) => voidState change event for the loaded variable.

ui module

Provides access to Dynamic’s UI.

PropertyTypeDescription
auth.show() => voidOpens up Dynamic’s authentication flow modal for your user to sign in. Automatically closes when finished.
auth.hide() => voidHide the Dynamic’s authentication flow modal.
userProfile.show() => voidOpens up Dynamic’s user profile modal, allowing your user to manage their profile and wallets.
userProfile.hide() => voidHide the Dynamic’s user profile modal
wallets.revealEmbeddedWalletKey(params: { type: "recovery-phrase" | "private-key" }) => voidOpens up Dynamic’s export embedded wallet key flow for the primary wallet.
Event nameTypeDescription
authFlowCancelled() => voidEmitted when the user cancels the authentication flow (closes it before completing it).
authFlowClosed() => voidEmitted when the authentication flow is closed, regardless of whether it was successfully completed or not.
authFlowOpened() => voidEmitted when the authentication flow is opened.

wallets module

Provides access to the user’s wallets.

PropertyTypeDescription
userWalletsBaseWallet[]The array of all the user’s wallets.
primaryBaseWallet | undefinedThe primary wallet of the user.
setPrimary(params: { walletId: string }) => Promise<void>Sets primary wallet of the user.
getBalance(params: { wallet: BaseWallet }) => Promise<{ balance: string }>Returns the balance of a wallet.
getNetwork(params: { wallet: BaseWallet }) => Promise<{ network: string | number }>Returns the network the wallet is connected to.
signMessage(params: { wallet: BaseWallet; message: string }) => Promise<{ signedMessage: string }>Signs a message with this wallet.
switchNetwork(params: { wallet: BaseWallet; chainId: string | number }) => Promise<void>Switches the wallet’s network.
Event nameTypeDescription
messageSigned(params: { messageToSign: string; signedMessage: string }) => voidEmitted when a message is signed.
walletAdded(params: { wallet: BaseWallet; userWallets: BaseWallet[] }) => voidEmitted when a wallet is added to the userWallets variable.
walletRemoved(params: { wallet: BaseWallet; userWallets: BaseWallet[] }) => voidEmitted when a wallet is removed from the userWallets variable.
primaryChanged(primary: BaseWallet | null) => voidState change event for the primary variable.
userWalletsChanged(userWallets: BaseWallet[]) => voidState change event for the userWallets variable.

wallets.embedded submodule

Allows interacting with and creating an embedded wallet for the current user.

PropertyTypeDescription
hasWalletbooleanWhether the logged in user has an embedded wallet.
getWallet() => BaseWallet | nullRetrieves the embedded wallet of the current user, or null if it doesn’t exist.
createWallet(params?: { chain?: "Evm" | "Sol" }) => BaseWallet Creates an embedded wallet for the current user.
Event nameTypeDescription
embeddedWalletCreated(verifiedCredential: JwtVerifiedCredential | null) => voidEmitted when an embedded wallet is created.
hasWalletChanged(hasWallet: boolean) => voidState change event for the hasWallet variable.

Extendable class

An object that can be extended by calling its .extend method with an Extension.

To extend here means to add or replace the existing properties of this object, as well as kicking off any related procedures. Like a structure on which you can attach lego bricks.

Since our client extends this class, you are able to easily pick and choose exactly which features you will need, maximizing the control, simplicity and package size of your project.

PropertyTypeDescription
extend<T>(extension: Extension<T>): T & typeof thisAllows you to extend the properties of the calling object and kick off related procedures.

Extension method

Extension<T>(extendable: Extendable, core: Core): T

A method that can be passed to the .extend method of an Extendable object to extend its properties and trigger related procedures.

We do not currently provide support on how to create your own custom extensions, though it can be achieved.