The React SDK supports automatically creating embedded wallets for your users when they login to your app. View this guide to learn more and configure automatic wallet creation.

To create a wallet with the React SDK, use the createWallet method from the useCreateWallet hook:

createWallet: async ({walletIndex?: number} | {createAdditional?: boolean}) => Promise<Wallet>

Usage

import {useCreateWallet} from '@privy-io/react-auth';
const {createWallet} = useCreateWallet();

Parameters

opts.createAdditional
boolean

Whether or not to create an additional Ethereum wallet for the user if they already have an existing Ethereum embedded wallet. Must be set to true to create additional wallets. Defaults to false. Learn more

opts.walletIndex
number

HD index to create the Ethereum wallet at. User must have an existing Ethereum embedded wallet in order to use this parameter.

Returns

wallet
Promise<Wallet>

A Promise for the linked account object for the created wallet.

Callbacks

You can optionally register an onSuccess or onError callback on the useCreateWallet hook.

const {createWallet} = useCreateWallet({
    onSuccess: ({wallet}) => {
        console.log('Created wallet ', wallet);
    },
    onError: (error) => {
        console.error('Failed to create wallet with error ', e)
    }
})
onSuccess
({wallet: Wallet}) => void

Optional callback to run after a user successfully creates a wallet.

onError
(error: string) => void

Optional callback to run after there is an error during wallet creation.