Magic Connect Mobile SDK API

Magic Connect Mobile SDK API

The constructor for the Native SDK's is MagicConnect. ⁠For React Native, the API methods require the magic-connect-extension to be added to the Magic SDK client to use, as would be done on Web. In all cases, the API methods live under the connect namespace.

#Constructor (Native)

Configure and construct your Magic Connect SDK instance.

#Arguments

MagicConnect(apiKey)

MagicConnect(apiKey, network?)

MagicConnect(apiKey, network?)

ParameterTypeDefinition
apiKeyStringYour publishable MC API Key retrieved from the Magic Dashboard.
network?EthNetwork(Enum): A representation of the connected Ethereum network (one of: mainnet, goerli).

customNodeConfiguration?

CustomNodeConfiguration

⁠(Object): A custom Ethereum Node configuration with the following shape:

⁠• rpcUrl (String): A URL pointing to your custom EVM Node.

⁠• chainId? (String): 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 a String.

#Example

Swift
Kotlin
Javascript
01import MagicSDK
02import UIKit
03
04@UIApplicationMain
05func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
06
07    // assign the newly created Magic instance to shared property
08    MagicConnect.shared = MagicConnect("YOUR_PUBLISHABLE_API_KEY");
09
10    return true
11}

#Connect Module

#getWalletInfo()

Returns information about the logged in user's wallet, such as the walletType.

#Arguments

None.

#Return Value

For Native clients, this returns a response with the wallet type as a String. For React Native clients, this returns a promise which will resolve to an object containing the wallet type. ⁠ ⁠Wallet type values can only be magic, metamask, coinbase_wallet, or wallet_connect.

Will throw an error if no user is logged in.

#Example

Swift
Kotlin
Javascript
01@IBAction func getWalletInfo() {
02    magic.connect.getWalletInfo(response: { response in
03        if (response.error != nil) {
04            print(response.error.debugDescription ?? "")
05        }
06        print(response.result?.description ?? "")
07    })
08}

#showWallet()

Will show the wallet view for an authenticated user. This can be used to let the user manage their wallet, purchase/send/receive crypto, access their recovery phrase, or end their session. This is only supported for users who log in with email or Google, not third-party wallets such as Metamask.

Note: Magic Connect currently has limited support for tokens and NFTs. We recommend using Zerion to view assets not visible by default in the Magic Connect wallet view. We are actively working on more robust, native coverage for tokens and NFTs.

#Arguments

None.

#Return Value

Returns a promise which will resolve when the user closes the wallet view.

#Example

Swift
Kotlin
Javascript
01@IBAction func showWallet() {
02    magic = MagicConnect.shared
03    magic.connect.showWallet(response: { response in
04            if (response.error != nil) {
05                print(response.error.debugDescription ?? "")
06            }
07            print(response.result?.description ?? "")
08        })
09    }

#requestUserInfo()

Will prompt the user to consent to share information with the requesting dApp. Currently returns only the user’s verified email address, which requires explicit user consent.

User info can be requested from any Email or Google login user. Additionally, Magic Connect Plus subscribers can use requestUserInfo() to collect a verified email address from third-party wallet users (MetaMask, Coinbase Wallet, etc.)

#Arguments (Native)

ParameterTypeDefinition
configuration:RequestUserInfoConfigurationisResponseRequired? (Boolean): When true the user will be required to complete the request.

#Arguments (React Native)

Parameter

Type

Definition

options?

Object | undefined

isResponseRequired?(Boolean): When true the user will be required to complete the request.

#Return Value

Returns a promise which will resolve to an object containing the requested information or rejects if the user declines to share information.

#Example

Swift
Kotlin
Javascript
01
02
03@IBAction func requestUserInfo() {
04    magic = MagicConnect.shared
05    magic.connect.requestUserInfo(response: { response in
06        if (response.error != nil) {
07            print(response.error.debugDescription ?? "")
08        }
09        print(response.result?.description ?? "")
10   })
11}

#disconnect()

Will disconnect the user from the dApp. This is similar to logging a user out. Will clear any third party wallet the user selected.

#Arguments

None.

#Return Value

None.

#Example

Swift
Kotlin
Javascript
01magic.connect.disconnect(response: { response in
02        print(response.result?.description)
03    })

Did you find what you were looking for?

Did you find what you were looking for?