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.network?String | Object(String): A representation of the connected Ethereum network (one of: mainnet, goerli). ⁠ ⁠(Object): A custom Ethereum Node configuration with the following shape: ⁠ ⁠• rpcUrl (String): A URL pointing to your custom EVM 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.extensions

Array

Array containing the ConnectExtension

#Example

import { Magic } from "magic-sdk"
import { ConnectExtension } from "@magic-ext/connect";

const magic = new Magic('YOUR_API_KEY', { 
  network: 'mainnet',
  extensions: [new ConnectExtension()]
});

#getWalletInfo()

Returns information about the logged in user's wallet, such as the walletType. Available starting with @magic-ext/connect 3.1.0.

#Arguments

None.

#Return Value

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

const walletInfo = await magic.connect.getWalletInfo();
console.log(walletInfo); // { walletType: "magic" | "metamask" | "coinbase_wallet" | "wallet_connect" }

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

const walletInfo = await magic.connect.getWalletInfo();
const walletType = walletInfo.walletType;

if (walletType === "magic") {
  await magic.connect.showWallet();
};

#requestUserInfo()

Will prompt the user to consent to sharing 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

ParameterTypeDefinition
options?Object | undefinedisResponseRequired? (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

const email = await magic.connect.requestUserInfo({ isResponseRequired: true });

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