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 |
---|---|---|
logout | () => void | Triggered when the user is logged out. |
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. |
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. |
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. |
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. |
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. |
userProfile.show | () => void | Opens up Dynamic’s user profile modal, allowing your user to manage their profile and wallets. |
wallets.revealEmbeddedWalletKey | (params: { type: "recovery-phrase" | "private-key" }) => void | Opens up Dynamic’s export embedded wallet key flow for the primary wallet. |
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. |
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 | () => BaseWallet | Creates an embedded wallet for the current user. Throws if one already exists. |
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?