Overview
Getting Started
The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic publishable key.Installation
Addmagic_sdk
to your pubspec.yaml
:
YAML
Bash
Performance improvement (optional)
We use service workers for for better performance on web3 operations. They are enabled by default on Android, but if you’d like to take advantage of this performance boost on iOS as well, you’d have to enable app bound domains. To do that, add the following to yourInfo.plist
and rebuild your app:
plist
Constructor
Magic()
Magic(apiKey, {MagicLocale locale})
Parameter | Type | Definition |
apiKey | String | Your publishable API Key retrieved from the Magic Dashboard. |
locale? | MagicLocale | Customize the language of Magic’s modal, email and confirmation screen. See Localization for more. |
Magic.eth(String apiKey, { required EthNetwork network, MagicLocale locale})
Parameter | Type | Definition |
network | EthNetwork | A representation of the connected Ethereum network (one of: mainnet or goerli). |
Magic.custom(String apiKey, { required String rpcUrl, int? chainId, MagicLocale locale})
Parameter | Type | Definition |
rpcUrl | String | A URL pointing to your custom Ethereum Node. |
chainId? | int | Some Node infrastructures require you to pass an explicit chain ID. If you are aware that your Node requires this configuration, pass it here as an integer. |
Initialization
Dart
Auth Module
The Auth Module and its members are accessible on the Magic SDK instance by theauth
property.
loginWithSMS
Authenticate a user passwordlessly using a one-time code sent to the specified phone number.
List of Currently Blocked Country Codes
Public Methods
Future<String> loginWithSMS({ required String email })
Parameter | Type | Definition |
phoneNumber | String | The phone number to log in with. |
Future<string>
The future resolves upon authentication request success and throws with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
Dart
loginWithEmailOTP
Authenticate a user passwordlessly using an email one-time code sent to the specified user’s email address.
Public Methods
Future<String> loginWithEmailOTP({ required String email })
Parameter | Type | Definition |
email | String | The user email to log in with. |
Future<string>
The future resolves upon authentication request success and throws with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
Dart
User Module
The User Module and it’s members are accessible on the Magic SDK instance by the user property.updateEmail
Initiates the update email flow that allows a user to change their email address.
Arguments
Future<bool> updateEmail({required String email, bool showUI = true})
Parameter | Type | Definition |
email | String | The new email to update to. |
showUI? | Boolean | If true , shows an out-of-the-box pending UI which includes instructions on which step of the confirmation process the user is on. Dismisses automatically when the process is complete. |
Future<boolean>
: The future resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails
Dart
getIdToken
Generates a Decentralized Id Token which acts as a proof of authentication to resource servers.
Arguments
Future<String> getIdToken({int lifespan = 900})
Parameter | Type | Definition |
lifespan? | int | Will set the lifespan of the generated token. Defaults to 900s (15 mins) |
Future<string>
: Base64-encoded string representation of a JSON tuple representing[proof, claim]
Dart
generateIdToken
Generates a Decentralized Id Token with optional serialized data.
Arguments
Future<String> generateIdToken({int lifespan = 900, String attachment = 'none'})
Parameter | Type | Definition |
lifespan? | int | Will set the lifespan of the generated token. Defaults to 900s (15 mins) |
attachment? | String | Will set a signature of serialized data in the generated token. Defaults to "none" |
Future<string>
: Base64-encoded string representation of a JSON tuple representing[proof, claim]
Dart
getInfo
Retrieves information for the authenticated user.
Arguments
- None
Future<UserInfo>
: an object containing the issuer, email and cryptographic public address of the authenticated user
Value | Type | Definition |
issuer | String | The Decentralized ID of the user. In server-side use-cases, we recommend this value to be used as the user ID in your own tables. |
email | String | Email address of the authenticated user. |
publicAddress | String | The authenticated user’s public address (a.k.a.: public key). Currently, this value is associated with the Ethereum blockchain. |
isMfaEnabled | Boolean | A boolean indicating if user has multi-factor authentication enabled. |
recoveryFactors | _ List<RecoveryFactor> _ value * type |
Dart
isLoggedIn
Checks if a user is currently logged in to the Magic SDK.
Arguments
- None
Future<Boolean>
Dart
logout
Logs out the currently authenticated Magic user
Arguments
- None
Future<Boolean>
Dart
OAuth Module
The OAuth Module and it’s members are accessible on the Magic SDK instance by theoauth
property.
loginWithPopup
Starts the OAuth 2.0 login flow.
Arguments
provider
(String): The OAuth provider being used for loginredirectURI
(String): A URL a user is sent to after they successfully log inscope?
(Array): Defines the specific permissions an application requests from a user
- None
Name | Argument |
'google' | |
'facebook' | |
'twitter' | |
Apple | 'apple' |
Discord | 'discord' |
GitHub | 'github' |
'linkedin' | |
Bitbucket | 'bitbucket' |
GitLab | 'gitlab' |
Twitch | 'twitch' |
Microsoft | 'microsoft' |
Dart