client
The base package that provides access to the Dynamic Client, which can be extended with extension packages.
Functions
createClient
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.
Param | Type | Description |
---|---|---|
environmentId | string | The ID of the environment of your dynamic application. |
apiBaseUrl | string? | Allows you to override the URL to which the SDK will make its API requests. |
cssOverrides | string? | Allows you to inject CSS into our UI modules (currently out of effect) |
appName | string? | How you’d like your app to be named in our copies. |
appLogoUrl | string? | 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.
Property | Type | Description |
---|---|---|
token | string | null | The JWT of the currently logged in user. |
authenticatedUser | UserProfile | null | The 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 name | Type | Description |
---|---|---|
authInit | (data: AuthEventPayload) => void | Emitted when the user initializes authentication, but before it either completes or fails. |
authSuccess | (user: UserProfile) => void | Emitted when the user successfully logs in. |
authFailed | (data: AuthEventPayload, reason: 'user-cancelled' | { error: unknown }) => void | Emitted when the user fails to log in. |
loggedOut | (user: UserProfile | null) => void | Emitted when the user logs out. |
userProfileUpdated | (user: UserProfile) => void | Emitted when the user’s profile is updated. |
authenticatedUserChanged | (authenticatedUser: UserProfile | null) => void | State change event for the authenticatedUser variable. |
tokenChanged | (token: string | null) => void | State change event for the token variable. |
auth.email
submodule
Provides methods to send, re-send and verify OTPs to email.
Property | Type | Description |
---|---|---|
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 name | Type | Description |
---|---|---|
emailVerificationFinished | (params: { isSuccess: boolean; destination: string }) => void | Emitted when the email verification process is completed. |
auth.sms
submodule
Provides methods to send, re-send and verify OTPs to phone numbers.
Property | Type | Description |
---|---|---|
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 name | Type | Description |
---|---|---|
smsVerificationFinished | (params: { isSuccess: boolean; destination: PhoneData }) => void | Emitted when the SMS verification process is completed. See PhoneData |
auth.social
submodule
Provides a method to connect social accounts.
Property | Type | Description |
---|---|---|
connect | (args: { provider: SocialProvider }) => Promise<void> | Requests social connection to the provided SocialProvider. |
networks
module
Provides access to the current network configurations.
Property | Type | Description |
---|---|---|
evm | GenericNetwork[] | Which EVM networks are currently configured. See GenericNetwork |
solana | GenericNetwork[] | Which Solana networks are currently configured. See GenericNetwork |
Event name | Type | Description |
---|---|---|
evmChanged | (evm: GenericNetwork[]) => void | State change event for the evm variable. |
solanaChanged | (solana: GenericNetwork[]) => void | State change event for the solana variable. |
sdk
module
Gives insight over the state of the SDK.
Property | Type | Description |
---|---|---|
loaded | boolean | Whether the SDK has loaded and is ready to handle requests. |
Event name | Type | Description |
---|---|---|
error | (error: Error | null) => void | Emitted when an error occurs. |
loadedChanged | (loaded: boolean) => void | State change event for the loaded variable. |
ui
module
Provides access to Dynamic’s UI.
Property | Type | Description |
---|---|---|
auth.show | () => void | Opens up Dynamic’s authentication flow modal for your user to sign in. Automatically closes when finished. |
auth.hide | () => void | Hide the Dynamic’s authentication flow modal. |
userProfile.show | () => void | Opens up Dynamic’s user profile modal, allowing your user to manage their profile and wallets. |
userProfile.hide | () => void | Hide the Dynamic’s user profile modal |
wallets.revealEmbeddedWalletKey | (params: { type: "recovery-phrase" | "private-key" }) => void | Opens up Dynamic’s export embedded wallet key flow for the primary wallet. |
Event name | Type | Description |
---|---|---|
authFlowCancelled | () => void | Emitted when the user cancels the authentication flow (closes it before completing it). |
authFlowClosed | () => void | Emitted when the authentication flow is closed, regardless of whether it was successfully completed or not. |
authFlowOpened | () => void | Emitted when the authentication flow is opened. |
wallets
module
Provides access to the user’s wallets.
Property | Type | Description |
---|---|---|
userWallets | BaseWallet[] | The array of all the user’s wallets. |
primary | BaseWallet | undefined | The 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 name | Type | Description |
---|---|---|
messageSigned | (params: { messageToSign: string; signedMessage: string }) => void | Emitted when a message is signed. |
walletAdded | (params: { wallet: BaseWallet; userWallets: BaseWallet[] }) => void | Emitted when a wallet is added to the userWallets variable. |
walletRemoved | (params: { wallet: BaseWallet; userWallets: BaseWallet[] }) => void | Emitted when a wallet is removed from the userWallets variable. |
primaryChanged | (primary: BaseWallet | null) => void | State change event for the primary variable. |
userWalletsChanged | (userWallets: BaseWallet[]) => void | State change event for the userWallets variable. |
wallets.embedded
submodule
Allows interacting with and creating an embedded wallet for the current user.
Property | Type | Description |
---|---|---|
hasWallet | boolean | Whether the logged in user has an embedded wallet. |
getWallet | () => BaseWallet | null | Retrieves 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 name | Type | Description |
---|---|---|
embeddedWalletCreated | (verifiedCredential: JwtVerifiedCredential | null) => void | Emitted when an embedded wallet is created. |
hasWalletChanged | (hasWallet: boolean) => void | State 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.
Property | Type | Description |
---|---|---|
extend | <T>(extension: Extension<T>): T & typeof this | Allows you to extend the properties of the calling object and kick off related procedures. |
Extension
method
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.
Was this page helpful?