Magic Connect SDK API

Magic Connect SDK API

The API methods live under the connect namespace and require the magic-connect-extension to be added to the Magic SDK client to use.

The constructor of the SDK is the same constructor used for Magic Auth and supports all the configuration options with one exception: ⚠️ We do not support the testMode argument in the constructor.

#Constructor

Configure and construct your Magic SDK instance.

#Arguments

new Magic(apiKey, options?)

ParameterTypeDefinition
apiKeyStringYour publishable API Key retrieved from the Magic Dashboard.
options.locale?StringCustomize the language of Magic's modal, email and confirmation screen. See Localization for more.
options.network?String | Object(String): A representation of the connected Ethereum network (one of: mainnet, rinkeby, kovan, or ropsten). ⁠ ⁠(Object): 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.
options.endpoint?StringA URL pointing to the Magic <iframe> application.

#Example

import { Magic } from 'magic-sdk';

let m;

// Construct with an API key:
m = new Magic('API_KEY');

// Construct with an API key and locale:
m = new Magic('API_KEY', { locale: 'es' });


// Construct with an API key plus options:
m = new Magic('API_KEY', { network: 'rinkeby', endpoint: '...' });

#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.

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.

email

string

The user’s email

#requestUserInfo()

Will prompt the user to consent to sharing information with the requesting dApp. For now, returns only the user’s email if consent is given.

#Arguments

None.

#Return Value

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

#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.

Did you find what you were looking for?

Did you find what you were looking for?