Skip to main content

Overview

Getting Started

The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic publishable key.

Installation

Add magic_sdk to your pubspec.yaml:
YAML
Run the following command to install dependencies:
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 your Info.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 the auth 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.
Example
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.
Example
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
Example
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]
Example
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]
Example
Dart

getInfo

Retrieves information for the authenticated user. Arguments
  • None
Returns
  • 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
Returns
  • Future<Boolean>
Example
Dart

logout

Logs out the currently authenticated Magic user Arguments
  • None
Returns
  • Future<Boolean>
Example
Dart

OAuth Module

The OAuth Module and it’s members are accessible on the Magic SDK instance by the oauth property.

loginWithPopup

Starts the OAuth 2.0 login flow. Arguments
  • provider (String): The OAuth provider being used for login
  • redirectURI (String): A URL a user is sent to after they successfully log in
  • scope? (Array): Defines the specific permissions an application requests from a user
Returns
  • None
Valid Providers Example
Dart

Resources