Create wallets on-demand with an email address, phone number, or any user identifier. Bring your own signer or use Crossmint’s managed Passkey signer. Compatible with any Viem account or EIP1193 compatible . Available on Polygon, Optimism, Base, Arbitrum Nova, and Astar today. If you are looking for a different chain, reach out to us at support@crossmint.io

Prerequisites:

  1. Create a Crossmint account if you haven’t yet.
  2. Go to the API key section of the developer console and create a new client-side API key with the following scopes: wallets.read, wallets.create, and wallets:nfts.read.
  3. Whitelist your project domain by adding it to the ‘Authorized Origins’ section when creating an API key. If testing locally, whitelist localhost and your port for development.
  4. Make a note of your API key, as you will need this to create wallets.

Creating a Wallet

To create a wallet, you need to pass the following parameters to the SDK:

  • email: User’s .
  • chain: Blockchain in which you’d like to create the wallet.
  • signer: An externally owned account which is used to control the smart contract wallet

See below for a sample initialization of the SDK to create a wallet using a Viem account. See more details in the quickstart:

import { Blockchain, CrossmintAASDK, EVMAAWallet, ViemAccount } from "@crossmint/client-sdk-aa";
import { english, generateMnemonic, mnemonicToAccount } from "viem/accounts";

const createAAWallet = async () => {
  const xm = CrossmintAASDK.init({
    apiKey: "your-api-key",
  });

  const email = "user@example.com";
  const chain = Blockchain.POLYGON;
  const mnemonic = generateMnemonic(english);
  const account = mnemonicToAccount(mnemonic) as any;

  const signer: ViemAccount = {
    type: "VIEM_ACCOUNT",
    account
  }

  const wallet = await xm.createWallet(email, chain, signer);
}

Choosing a signer

Crossmint supports any EIP1193 compatible provider or any Viem account to be used to create a wallet. See examples below on instantiating a wallet with different signer types:

Web3Auth

Generate a smart wallet with a provider from web3auth.

You must first create a project and a unique custom verifier in web3auth. Read more about custom verifiers here.

const createAAWallet = async () => {
  const xm = CrossmintAASDK.init({
    apiKey: <api-key> || '', //From the Crossmint developer console
  });
  const web3AuthSigner: Web3AuthSigner = {
    type: "WEB3_AUTH",
    clientId: <client-id>, // From the web3auth console
    web3AuthNetwork: "sapphire_devnet" | "sapphire_mainnet", // "sapphire_devnet for testnet, sapphire_mainnet for prod"
    verifierId: "<verifierID>", // The unique verifier ID you set in web3auth
    jwt: "<jwt>", // The JWT from your user
  };
  const wallet = await xm.getOrCreateWallet(
    userIdentifier,
    Blockchain.<chain>,
    { signer: web3AuthSigner }
  );
}

Custom EIP1193 Provider

You can bring any EIP1193 compatible provider to create a wallet. This includes any embedded EOA solution or injected EOA which you may be using in your dapp. The below example gets a provider from an injected wallet (like Metamask) provider to create a wallet:

const createAAWalletHelperMM = async () => {
    if (!window.ethereum) {
        console.error("Ethereum wallet is not available. Please install MetaMask or another compatible wallet.");
        return;
    }

    try {
        // Prompt user to enable MetaMask (or another wallet) if it's not already enabled
        await window.ethereum.request({ method: "eth_requestAccounts" });
    } catch (error) {
        console.error("Error accessing Ethereum accounts:", error);
        return;
    }

    const xm = CrossmintAASDK.init({
        apiKey: process.env.NEXT_PUBLIC_API_KEY || "",
    });

    const wallet = await xm.getOrCreateWallet(userIdentifier, Blockchain.POLYGON_AMOY, { signer: window.ethereum });
};