Connect or create a wallet
You can also use Privy to connect a user’s external wallet if they have one, or to create an embedded wallet for them if they do not. This ensures users always have a connected wallet they can use with your application, and allows them to choose to use their external wallet if preferred.
To do so, use the connectOrCreateWallet
method of the usePrivy
hook:
This method will prompt the user to connect an external wallet, or log in with email, SMS, or socials, depending on your configured loginMethods
, to create an embedded wallet.
Privy’s connectOrCreate
interface currently only supports external and embedded wallets on EVM
networks.
For example, you might have a “Connect” button in your app that prompts users to connect their wallet, like so:
This method functions exactly the same as Privy’s login
method, except when users connect their
external wallet, they will not automatically be prompted to authenticate that wallet by signing a
message
Callbacks
You can optionally pass callbacks to the useConnectOrCreateWallet
hook to run custom logic after connecting a wallet or to handle errors.
onSuccess
Parameters
The most recently connected wallet.
onError
Parameters
The error that occurred during the this flow.
Was this page helpful?