Getting Started with Test Mode for Magic SDK

Getting Started with Test Mode for Magic SDK

Magic client SDKs provide Test Mode as a quick way to test your integration locally by asserting specific error codes or bypassing the magic link flow completely.


To enable Test Mode, provide testMode: true to the SDK constructor.

import { Magic } from 'magic-sdk';

const magic = new Magic('YOUR_API_KEY', {
  testMode: true,

With Test Mode enabled, you can assert the desired behavior through the email address you provide to loginWithMagicLink.

To assert a success state, use

magic.auth.loginWithMagicLink({ email: '' });

Users created in test mode are ephemeral. It is advised that you do not associate these users to persistent data in your backend. If you are building an integration with cryptocurrency or Web3 features, please take a look at the advanced usage section below.

To assert a failed state, use

magic.auth.loginWithMagicLink({ email: '' });

To assert a case-specific failed state, you can also provide an RPC error code with test+fail_with_{RPC_ERROR_CODE}

import { RPCErrorCode } from 'magic-sdk';

magic.auth.loginWithMagicLink({ email: `test+fail_with_{${RPCErrorCode.MagicLinkFailedVerification}}` });
magic.auth.loginWithMagicLink({ email: `test+fail_with_{${RPCErrorCode.MagicLinkExpired}}` });
magic.auth.loginWithMagicLink({ email: `test+fail_with_{${RPCErrorCode.MagicLinkRateLimited}}` });

You can find a list of relevant RPC error codes here.

#Advanced Usage

Web3 and blockchain use-cases sometimes require access to deterministic key-pairs so that testnet funds are available at runtime. To enable this, users can explicitly specify the key-pair associated to a test user, like so:


The key-pair provided in the email address during test mode is not protected by Magic's delegated key management system. These keys should not be considered secure or private. Never store mainnet funds with these keys!

In practice, you can assert a successful login with:


In the example above, we encode an Ethereum-compatible key-pair in the test user's email address. The login method will immediately resolve with a success state, bypassing the passwordless flow and enabling Ethereum or EVM-compatible signing methods to work seamlessly with your existing Web3 code.

Did you find what you were looking for?

Getting Started with Test Mode for Magic SDK

Did you find what you were looking for?