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

Functions

DynamicSDK.init

DynamicSDK init({
    required ClientProps props,
})

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

Objects

ClientProps

The parameters that are acceptable by the DynamicSDK.init 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.
logLevelLoggerLevel?Allows you to set the level of the logs to the console

DynamicSDK.instance

The base object of a client.

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

It is composed of properties which we call modules. Note that all modules have state properties and implement one or more streams.

For every property that is a state, there will always be a stream named with the same name plus "Changes", 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.
logoutFuture<void> logout()Allows you to log the current user out.

auth.email submodule

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

PropertyTypeDescription
sendOTPFuture<void> sendOTP(String email)Sends an OTP token to the target email.
resendOTPFuture<void> resendOTP()Sends another OTP token to the same email as the last call to sendOTP.
verifyOTPFuture<void> verifyOTP(String token)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.

PropertyTypeDescription
sendOTPFuture<void> sendOTP(PhoneData phoneData)Sends an OTP token to the target PhoneData.
resendOTPFuture<void> resendOTP()Sends another OTP token to the same phone number as the last call to sendOTP.
verifyOTPFuture<void> verifyOTP(String token)Receives an OTP token and logs the user in if it is valid.

sdk module

Gives insight over the state of the SDK.

PropertyTypeDescription
loadedbooleanWhether the SDK has loaded and is ready to handle requests.

ui module

Provides access to Dynamic’s UI.

PropertyTypeDescription
showAuthvoidOpens up Dynamic’s authentication flow modal for your user to sign in. Automatically closes when finished.
showUserProfilevoidOpens up Dynamic’s user profile modal, allowing your user to manage their profile and wallets.

wallets module

Provides access to the user’s wallets.

PropertyTypeDescription
userWalletsBaseWallet[]The array of all the user’s wallets.
primaryBaseWallet | nullThe primary wallet of the user.
setPrimaryFuture<void> setPrimary({required String walletId})Sets primary wallet of the user.
getBalanceFuture<String> getBalance({required BaseWallet wallet})Returns the balance of a wallet.
getNetworkFuture<Network> getNetwork({required BaseWallet wallet})Returns the network the wallet is connected to.
signMessageFuture<String> signMessage({required BaseWallet wallet, required String message})Signs a message with this wallet.
switchNetworkFuture<void> switchNetwork({required BaseWallet wallet, required Network network})Switches the wallet’s network.

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.
getWalletBaseWallet | nullRetrieves the embedded wallet of the current user, or null if it doesn’t exist.
createWalletBaseWallet Creates an embedded wallet for the current user. Throws if one already exists.