The useCreateWallet hook provides functionality to create new blockchain wallets for the authenticated user.

Import

import { useCreateWallet } from "@getpara/react-sdk@alpha";

Usage

function WalletCreator() {
  const { createWallet, createWalletAsync, isPending, error } = useCreateWallet();
  const { refetch: refetchAccount } = useAccount();

  const handleCreateWallet = async () => {
    try {
      const result = await createWalletAsync({
        wallets: [
          { type: "EVM" },
          { type: "SOLANA" }
        ]
      });

      console.log("Created wallets:", result.wallets);
      await refetchAccount();
    } catch (err) {
      console.error("Failed to create wallets:", err);
    }
  };

  return (
    <button 
      onClick={handleCreateWallet}
      disabled={isPending}
    >
      {isPending ? "Creating..." : "Create EVM & Solana Wallets"}
    </button>
  );
}

Parameters for createWallet/createWalletAsync

The mutation functions accept a CreateWalletParams object with the following structure:

interface CreateWalletParams {
  wallets: WalletCreationSpec[];
}

interface WalletCreationSpec {
  type: 'EVM' | 'SOLANA' | 'COSMOS';
}

Response Structure

When successful, the mutation returns a CreateWalletResponse object:

interface CreateWalletResponse {
  wallets: Wallet[];
}

interface Wallet {
  id: string;
  type: 'EVM' | 'SOLANA' | 'COSMOS';
  address: string;
}

Example: Conditional Wallet Creation

function ConditionalWalletCreator() {
  const { createWalletAsync } = useCreateWallet();
  const { data: account } = useAccount();
  const [walletType, setWalletType] = useState<TWalletType>("EVM");

  const createWalletIfNeeded = async () => {
    if (!account?.isConnected) return;

    const hasWalletType = account.wallets.some(w => w.type === walletType);
    
    if (hasWalletType) {
      console.log(`User already has ${walletType} wallet`);
      return;
    }

    try {
      const result = await createWalletAsync({
        wallets: [{ type: walletType }]
      });
      
      console.log(`Created ${walletType} wallet:`, result.wallets[0]);
    } catch (err) {
      console.error("Wallet creation failed:", err);
    }
  };

  return (
    <div>
      <select 
        value={walletType} 
        onChange={(e) => setWalletType(e.target.value as TWalletType)}
      >
        <option value="EVM">EVM</option>
        <option value="SOLANA">Solana</option>
        <option value="COSMOS">Cosmos</option>
      </select>
      
      <button onClick={createWalletIfNeeded}>
        Create {walletType} Wallet
      </button>
    </div>
  );
}

Events

The wallet creation process triggers a WalletCreatedEvent that can be listened to via the ParaProvider callbacks:

<ParaProvider
  callbacks={{
    onWalletCreated: (event) => {
      console.log("New wallet created:", event.detail);
    }
  }}
>
  {/* Your app */}
</ParaProvider>

Notes

  • This hook requires the user to be authenticated before creating wallets
  • The hook automatically invalidates account queries on success to refresh wallet lists
  • Multiple wallets can be created in a single mutation by passing multiple specifications
  • Each wallet type (EVM, SOLANA, COSMOS) can only be created once per user