Overview
Getting Started
The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic publishable key.Performance improvement (optional)
We use service workers for for better performance on web3 operations. If you’d like to take advantage of this performance boost, you’d have to enable app bound domains. To do that, add the following to yourInfo.plist
and rebuild your app:
plist
Constructor
Magic()
Parameter | Type | Definition |
apiKey | String | Your publishable API Key retrieved from the Magic Dashboard. |
network? | EthNetwork | CustomNodeConfiguration | (EthNetwork ): A representation of the connected Ethereum network (.mainnet or .goerli ).( CustomNodeConfiguration ): A custom Ethereum Node configuration with the following shape:rpcUrl (String): A URL pointing to your custom Ethereum Node. chainId? (Number): 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. |
locale? | Locale | Customize the language of Magic’s modal, email and confirmation screen. See Localization for more. |
Initialization
InAppDelegate
Swift
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
Arguments
configuration
(LoginWithSMSConfiguration):phoneNumber
(string): The user phone number to log in withshowUI
(boolean): Iftrue
, show an out-of-the-box pending UI while the request is in flight
Promise<string | null>
: The promise resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
Swift
Swift
loginWithEmailOTP
Authenticate a user passwordlessly using an email one-time code sent to the specified user’s email address.
Arguments
configuration
(LoginWithEmailOTPConfiguration):email
(string): The user email to log in with
Promise<string | null>
: The promise resolves upon authentication request success and rejects with a specific error code if the request fails. The resolved value is a Decentralized ID token with a default 15-minute lifespan.
Swift
Swift
Wallet Module
The Wallet Module and its members are accessible on the Magic SDK instance by thewallet
property.
connectWithUI
Renders a simple login form UI to collect the user’s email address and authenticate them passwordlessly using a one-time passcode (OTP) sent to their email address they input.
Arguments
- None
- A
promiEvent
which returns anString[]
when resolved: An array of user accounts that are connected, with the first element being the current public address of the user. You can read more on PromiEvents here.
Swift
showUI
Displays the fully navigable wallet to the user that adheres to the toggled configurations on your developer dashboard’s Widget UI tab. This is only supported for users who login with email or Google. User must be signed in for this method to return or else it will throw an error.
Arguments
- None
Promise
which resolves when the user closes the window
Swift
User Module
The User Module and its members are accessible on the Magic SDK instance by theuser
property.
updateEmail
Initiates the update email flow that allows a user to change to a new email.
Arguments
configuration
(UpdateEmailConfiguration):email
(string): The user email to update withshowUI
(boolean): Iftrue
, show an out-of-the-box pending UI while the request is in flight
Promise<Bool>
: The promise resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails
Swift
getIdToken
Generates a Decentralized Id Token which acts as a proof of authentication to resource servers.
Arguments
configuration
(GetIdTokenConfiguration):lifespan
(number): will set the lifespan of the generated token. Defaults to 900s (15 mins).
Promise<String>
: Base64-encoded string representation of a JSON tuple representing[proof, claim]
Swift
generateIdToken
Generates a Decentralized Id Token with optional serialized data.
Arguments
configuration
(GenerateIdTokenConfiguration):lifespan
(number): will set the lifespan of the generated token. Defaults to 900s (15 mins).attachment
(str): will set a signature of serialized data in the generated token. Defaults to"none"
.
Promise<String>
: Base64-encoded string representation of a JSON tuple representing[proof, claim]
Swift
getInfo
Retrieves information for the authenticated user.
Arguments
- None
Promise<UserInfo>
- The issuer, email and cryptographic public address of the authenticated user.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 userphoneNumber
(string): Phone number of the authenticated userpublicAddress
(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 enabledrecoveryFactors
(RecoveryFactor):value
(string): Recovery value such as phone numbertype
(RecoveryMethodType): The method used for account recovery
Swift
isLoggedIn
Checks if a user is currently logged in to the Magic SDK.
Arguments
- None
Promise<Bool>
: A boolean value indicating if a user is logged in
Swift
logout
Logs out the currently authenticated Magic user. Arguments- None
Promise<Bool>
: A boolean value indicating if a user has been logged out
Swift
showSettings
Displays an iframe with the current user’s settings. Allows for users to update their email address, enable multi-factor authentication, and add a recovery factor.
Access to MFA and account
recovery require paid add-ons.
- None
Promise
which resolves when the user closes the window
Swift
updatePhoneNumber
Initiates the update phone number flow that allows a user to change their phone number.
Arguments
configuration
:phoneNumber
(str): The user phone number to update with
PromiEvent<boolean>
: The promise resolves with a true boolean value if update email is successful and rejects with a specific error code if the request fails
Swift
recoverAccount
Initiates the account recovery flow that allows a user to recover their account using their email address.
Arguments
configuration
(RecoverAccountConfiguration):email
(str): The user email address to recover account with
PromiEvent<boolean>
: The promise resolves with a true boolean value if the account recovery is successful and rejects with a specific error code if the request fails
Swift
Error Handling
There are three types of error class to be aware of when working with Magic’s iOS SDK:Provider
Swift
Network
Swift
Events
Swift