@crossmint/client-sdk-smart-wallet v0.3.16
Smart Wallet SDK
!WARNING Smart Wallet SDK is no longer maintained, use Wallets SDK instead.
A client-side SDK for interacting with Crossmint Smart Wallets. This SDK enables developers to create and manage smart contract wallets that support both traditional keypair-based signing and passkey authentication.
Installation
npm install @crossmint/client-sdk-smart-wallet
# or
pnpm add @crossmint/client-sdk-smart-walletAuthentication
This SDK uses JSON Web Tokens (JWT) to authenticate your users. JWT is generated by the auth server and used to authorize users to deploy and operate their wallets.
For detailed instructions on how to obtain a JWT token, please refer to User Auth.
Quick Start
import { SmartWalletSDK } from "@crossmint/client-sdk-smart-wallet";
import { privateKeyToAccount } from "viem";
const sdk = SmartWalletSDK.init({ clientApiKey: "<YOUR_API_KEY>" });
const account = privateKeyToAccount(privateKey);
const wallet = await sdk.getOrCreateWallet(
  {
    jwt: "<USER_TOKEN>",
  },
  "base-sepolia",
  {
    signer: {
      type: "VIEM_ACCOUNT",
      account,
    },
  }
);
const address = wallet.address;Examples
Wallet Creation
Passkey Wallets
const signer = await sdk.createPasskeySigner("My Wallet")
const wallet = await sdk.getOrCreateWallet(
  {
    jwt: "<USER_TOKEN>",
  },
  "base-sepolia",
  {
    signer,
  }
);
const address = walletClient.getAddress();Private Key Wallets
import { privateKeyToAccount } from "viem";
const account = privateKeyToAccount(privateKey);
const wallet = await sdk.getOrCreateWallet(
  {
    jwt: "<USER_TOKEN>",
  },
  "base-sepolia",
  {
    signer: {
      type: "VIEM_ACCOUNT",
      account,
    },
  }
);
const address = walletClient.getAddress();Browser Wallets
import type { EIP1193Provider } from "viem";
const providerSigner = window.ethereum as EIP1193Provider;
const wallet = await sdk.getOrCreateWallet(
  {
    jwt: "<USER_TOKEN>",
  },
  "base-sepolia",
  {
    signer: providerSigner,
  }
);Sending Transactions
import { encodeFunctionData, erc20Abi } from "viem";
const walletClient = wallet.client.wallet;
const txHash = await walletClient.sendTransaction({
  to: "<TOKEN_ADDRESS>",
  data: encodeFunctionData({
    abi: erc20Abi,
    functionName: "transfer",
    args: ["<RECEIVER_ADDRESS>", "<TRANSFER_AMOUNT>"],
  })
})Signing Messages
const walletClient = wallet.client.wallet;
const signature = await walletClient.signMessage({
  message: "Hello, Crossmint!"
})Migrating from 0.1.x
0.2.x SDK strives to be backwards-compatible with 0.1.x as much as possible.
However, since the wallets are now powered by Crossmint API, some functionality is not available anymore.
Specifically, some functions from the SmartWalletClient object are not available anymore:
- request
- writeContract
- deployContract
- account
- sendUserOperation
- prepareUserOperationRequest
Additionally, the passkey creation flow is changed. To create a passkey-powered wallet, you first create a passkey signer:
const signer = await sdk.createPasskeySigner("My Wallet")Then use that signer during wallet creation:
const wallet = await sdk.getOrCreateWallet(
  {
    jwt: "<USER_TOKEN>",
  },
  "<NETWORK>",
  {
    signer,
  }
);API Reference
SmartWalletSDK
The main entry point for interacting with smart wallets.
Static Methods
init(params: SmartWalletSDKInitParams): SmartWalletSDK
Initializes the SDK with your client-side API key.
const sdk = SmartWalletSDK.init({ clientApiKey: "<YOUR_API_KEY>" });Instance Methods
getOrCreateWallet(user: UserParams, chain: SmartWalletChain, walletParams: WalletParams): Promise<EVMSmartWallet>
Creates or retrieves a smart wallet for the specified user.
const wallet = await sdk.getOrCreateWallet(
  {
    jwt: "<USER_TOKEN>" 
  },
  "<NETWORK>",
  {
    signer: /* PasskeySigner or ExternalSigner */
  }
);createPasskeySigner(name: string): Promise<PasskeySigner>
Creates a new passkey signer with the given name.
const signer = await sdk.createPasskeySigner("My Wallet");Types
SmartWalletChain
Supported blockchain networks.
WalletParams
Configuration for wallet creation:
interface WalletParams {
  signer: ExternalSigner | PasskeySigner;
}
// Use existing Web3 wallet or private key
type ExternalSigner = EIP1193Provider | ViemAccount;
// Use private key authentication
interface ViemAccount {
  type: "VIEM_ACCOUNT";
  account: LocalAccount & { source: "custom" };
};
// Use passkey authentication
interface PasskeySigner {
  type: "PASSKEY";
  credential: WebAuthnP256.P256Credential;
}EVMSmartWallet
The wallet instance returned by getOrCreateWallet(). Provides methods for interacting with the smart wallet:
interface EVMSmartWallet {
  // viem clients that provide an interface for core wallet functionality.
  client: {
      public: PublicClient<HttpTransport>;
      wallet: SmartWalletClient;
  };
  // The EVM chain of the smart wallet.
  chain: SmartWalletChain;
  // The address of the smart wallet.
  address(): Address;
  // Transfers tokens from the smart wallet to a specified address.
  transferToken(toAddress: Address, config: TransferType): Promise<string>;
  // A list of NFTs owned by the wallet.
  nfts(): Promise<NftResponse>;
  // Sends a contract call transaction and returns the hash of a confirmed transaction.
  executeContract(params: {
    address: Address;
    abi: Abi;
    functionName: string;
    args: unknown;
  }): Promise<Hex>;
}SmartWalletClient
The client instance available via wallet.client.wallet. Provides methods for interacting with the wallet:
interface SmartWalletClient {
  // Get the wallet's address
  getAddress(): Address;
  
  // Sign a message
  signMessage(message: string): Promise<Hex>;
  
  // Sign typed data (EIP-712)
  signTypedData<T extends TypedData>(params: TypedDataDefinition<T>): Promise<Hex>;
  
  // Send a transaction
  sendTransaction(params: {
    to: Address;
    data?: Hex;
    value?: bigint;
  }): Promise<Hex>;
}Full reference is available in the docs.
8 months ago
7 months ago
7 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
6 months ago
8 months ago
8 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
11 months ago
11 months ago
11 months ago
12 months ago
11 months ago
11 months ago
11 months ago
11 months ago
8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago