Skip to main content

magicLink

A wallet configurator for Magic Wallet which allows integrating the wallet with React

import { magicLink } from "@thirdweb-dev/react";

const magicLinkConfig = magicLink({
apiKey: "MAGIC_API_KEY,
});
customize (optional)

magicLinkConfig contains the default config for metadata and UI. you can optionally choose to override the defaults to customize the wallet. Learn more about these configs

const magicLinkConfig = magicLink({ ... });

// override metadata
magicLinkConfig.meta.name = "..."; // change the name
magicLinkConfig.meta.iconURL = "..."; // change the icon
magicLinkConfig.meta.urls = {
// change urls to download the wallet on various platforms
android: "https://...",
ios: "https://...",
chrome: "https://...",
firefox: "https://...",
};

// override connection UI
magicLinkConfig.connectUI = MagicLinkConnectUI; // react component

// custom selection UI
magicLinkConfig.selectUI = MagicLinkSelectUI; // react component

Once the config is ready, you can use it with ConnectWallet component or useConnect hook as shown below

// add to ThirdwebProvider to add it in ConnectWallet's modal
<ThirdwebProvider supportedWallets={[magicLinkConfig]} />;

// or use it with useConnect hook
const connect = useConnect();
connect(magicLinkConfig, { ... });

apiKey

Your Magic Link apiKey. You can get an API key by signing up for an account on Magic Link's website.

Must be a string.

magicSdkConfiguration (optional)

Configuration for Magic Auth SDK.

{
locale?: string;
endpoint?: string;
testMode?: boolean;
}
locale (optional)

Customize the language of Magic's modal, email and confirmation screen. See Localization for more.

endpoint (optional)

A URL pointing to the Magic iframe application.

testMode (optional)

Enable testMode to assert the desired behavior through the email address you provide to loginWithMagicLink without having to go through the auth flow.

smsLogin (optional)

Specify whether you want to allow users to login with their phone number or not. It is true by default

Must be a boolean.

emailLogin (optional)

Specify whether you want to allow users to login with their email or not. It is true by default

Must be a boolean.

Usage with ConnectWallet

To allow users to connect to this wallet using the ConnectWallet component, you can add it to ThirdwebProvider's supportedWallets prop.

<ThirdwebProvider
supportedWallets={[
magicLink({
apiKey: "MAGIC_API_KEY",
}),
]}
>
<YourApp />
</ThirdwebProvider>

Usage with useConnect

you can use the useConnect hook to programmatically connect to the wallet without using the ConnectWallet component.

The wallet also needs to be added in ThirdwebProvider's supportedWallets if you want the wallet to auto-connect on next page load.

Calling connect opens the Magic's Modal and prompts the user to either enter an OTP sent to their phoneNumber or click on the link sent to their email.

const magicLinkConfig = magicLink({
apiKey: "MAGIC_API_KEY",
});

function App() {
const connect = useConnect();

const handleConnect = async () => {
await connect(magicLinkConfig, connectOptions);
};

return <div> ... </div>;
}

connectOptions

{
// one of these is required
email?: string;
phoneNumber?: string;

chainId?: number;
}
chainId (optional)

If chainId is provided, wallet will be connected and immediately switch to network with given chainId.

Chain object corresponding to this chainId from @thirdweb-dev/chains package must be specified in ThirdwebProvider's supportedChains prop as shown below

import { Polygon } from "@thirdweb-dev/chains";
import { ThirdwebProvider } from "@thirdweb-dev/react";

export function YourApp() {
return (
<ThirdwebProvider supportedChains={[Polygon]}>
<App />
</ThirdwebProvider>
);
}
email or phoneNumber

specify either email or phoneNumber of the user to connect to your app.

If you call the connect function with email, a modal will open and prompt the user to click on the link sent to their email. Once user completes this step, the modal will close and the user will be connected to your app.

If you call the connect method with phoneNumber, a modal will open and prompt the user to enter the OTP sent to their phone number. Once the user enters the OTP, the modal will close and the user will be connected to your app.