yarn add @web3-react/magic-connector
apiKey: string
networks: Network[]
endpoint?: string
// where Network is defined below
export interface Network {
rpcUrls: string[];
chainId: number;
blockExplorerUrls: string[];
}
import { MagicConnector } from '@web3-react/magic-connector'
const networks = [
{
rpcUrls: [`https://mainnet.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_API_KEY}`],
chainId: 1,
blockExplorerUrls: ['https://etherscan.io']
},
{
rpcUrls: [`https://rpc-mainnet.maticvigil.com/v1/${process.env.NEXT_PUBLIC_MATIC_VIGIL_API_KEY}`],
chainId: 137,
blockExplorerUrls: ['https://explorer-mainnet.maticvigil.com']
}
]
const magic = new MagicConnector({ apiKey: '…', networks })
Note: Once the connector has been activated, the Magic SDK instance can be accessed under the .magic
property.
Happens when the user closes the connection window.
import { UserRejectedRequestError } from '@web3-react/magic-connector'
function Component() {
const { error } = useWeb3React()
const isNoEthereumProviderError = error instanceof UserRejectedRequestError
// ...
}
Happens when the Magic link verification fails.
import { FailedVerificationError } from '@web3-react/magic-connector'
function Component() {
const { error } = useWeb3React()
const isNoEthereumProviderError = error instanceof FailedVerificationError
// ...
}
Happens when the Magic rate limit has been reached.
import { MagicLinkRateLimitError } from '@web3-react/magic-connector'
function Component() {
const { error } = useWeb3React()
const isNoEthereumProviderError = error instanceof MagicLinkRateLimitError
// ...
}
Happens when the Magic link has expired.
import { MagicLinkExpiredError } from '@web3-react/magic-connector'
function Component() {
const { error } = useWeb3React()
const isNoEthereumProviderError = error instanceof MagicLinkExpiredError
// ...
}