<v13.2.0
<v13.2.0
#Version
This document is for magic-sdk
version 13.1.0
and below. You can view the open-source repository for this SDK on Github and all versioned releases on NPM.
Note: This version of the SDK is outdated and we advise upgrading to 13.1.0
or newer as soon as possible. Although there are no breaking changes between versions, we will still provide support for this version until further notice.
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?)
Parameter | Type | Definition |
apiKey | String | Your 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. |
| Array | Array containing the |
#Example
01import { Magic } from "magic-sdk"
02import { ConnectExtension } from "@magic-ext/connect";
03
04const magic = new Magic('YOUR_API_KEY', {
05 network: 'mainnet',
06 extensions: [new ConnectExtension()]
07});
#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
01const walletInfo = await magic.connect.getWalletInfo();
02console.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
01const walletInfo = await magic.connect.getWalletInfo();
02const walletType = walletInfo.walletType;
03
04if (walletType === "magic") {
05 await magic.connect.showWallet();
06};
#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
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
01
02const 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.