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})
Magic.eth(String apiKey, { required EthNetwork network, MagicLocale locale})
Magic.custom(String apiKey, { required String rpcUrl, int? chainId, MagicLocale locale})
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 })
Returns
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 })
Returns
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})
Returns
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})
Returns
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'})
Returns
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
Example
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
Example
Dart