Create Smart Wallets
Generate wallets for your users
Prerequisites:
- Create a Crossmint account if you haven’t yet.
- 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
, andwallets:nfts.read
. - 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 (e.g.
localhost:3000
) for development. - Make a note of your API key, as you will need this to create wallets.
Creating a Wallet
To create a wallet, you will use the getOrCreateWallet
function of the SmartWalletSDK
, which takes the following parameters:
An object identifying the user and containing the following properties:
jwt
- JSON web token from your auth provider
The blockchain you intend to create the smart contract wallet on. Available options:
polygon
polygon-amoy
base
base-sepolia
arbitrum
arbitrum-sepolia
optimism
optimism-sepolia
If you are looking for a different chain, reach out to sales.
An object containing a signer
property. Read on to learn what is a signer and the different types available.
The way that you call the getOrCreateWallet
function will depend on the type of signer your application is utilizing.
import { SmartWalletChain, SmartWalletSDK } from "@crossmint/client-sdk-smart-wallet";
import { getJWTFromAuth } from "./FirebaseAuthManager";
export const createSmartWalletPasskey = async () => {
const xm = SmartWalletSDK.init({
clientApiKey: process.env.REACT_APP_CROSSMINT_API_KEY_STG,
});
const jwt = await getJWTFromAuth();
return await xm.getOrCreateWallet({ jwt }, SmartWalletChain.POLYGON_AMOY);
}
The getOrCreateWallet
function returns a EVMSmartWallet
object, which contains the following properties:
address
- The address of the created walletchain
- The chain the wallet was created onclient
- A Viem client for interacting with the wallet
As well as some helper functions to interact with the wallet such as:
nfts
- A function to get the NFTs owned by the walletexecuteContract
- A function to execute a contract on the wallettransferToken
- A function to transfer tokens owned by the wallet