Skip to main content

Using the embedded wallet

note

To use embedded wallets in your app, please upgrade your @privy-io/react-auth version to at least 1.16.0.

Once your user has created an embedded wallet, they can take wallet-based actions in your app, such as signing messages, sending and receiving assets, and more.

Getting the wallet address

When your user creates an embedded wallet, that wallet becomes the active wallet for that user. You can access your user's active (embedded) wallet at user.wallet to get their address and more.

const embeddedWallet = user.wallet?.address;

Alternatively, you can also access the user's embedded wallet from the user.linkedAccounts array of the user object. The entry in user.linkedAccounts corresponding to the embedded wallet will have a type of 'wallet' and a walletClient of 'privy'.

const embeddedWallet = user.linkedAccounts.find((account) => (account.type === 'wallet' && account.walletClient === 'privy'));

Signing messages

To prompt your user to sign a message with their embedded wallet, use the signMessage method from the usePrivy hook. As a parameter to the method, specify the message you'd like your user to sign as a string.

When invoked, signMessage will open a Privy modal that displays your message to your user and prompts them to sign it with their embedded wallet. The method returns a Promise for the user's signature as a string.

Embedded wallet signature flow

Signing a message with the embedded wallet. You can customize the text shown on this screen.

You can also customize the text on the signature modal by passing in a JSON configuration object as an optional second parameter to signMessage. You can include the following configurations in the object as strings:

  • title: the title text for the signature screen. Defaults to 'Sign'.
  • description: a description for the action the user is taking. Defaults to 'Sign to continue'.
  • buttonText: the text to show on the signing button. Defaults to 'Sign and Continue'.

Below is an example sign message button configured with custom text for the modal.

Example Sign Message Button
import { usePrivy } from '@privy-io/react-auth';

function SignMessageButton() {
const { user, signMessage } = usePrivy();
// Replace this with the message you'd like your user to sign
const message = 'Hello world';
// Replace this with the text you'd like on your signature modal
const config = {
title: 'Sample title text',
description: 'Sample description text',
buttonText: 'Sample button text'
};

// Users must have an embedded wallet at `user.wallet` to sign a message.
return (
<button disabled={!user.wallet} onClick={async () => {
const signature = await signMessage(message, config);
// Use `signature` however you'd like
}}>
Sign
</button>);
}
info

Embedded wallet accounts cannot be unlinked from a user account after creation.


note

The sections below are 🚧 under construction 🚧 and are liable to change as part of our phased rollout. This is simply meant to provide a sense for the interfaces and features we plan to support.

Sending transactions

To prompt your user to send an Ethereum transaction with their embedded wallet, you will be able to use the sendTransaction method from the usePrivy hook. As method parameters, you will be able to specify:

  • the destination address
  • the value of the transaction
  • the gas limit and gas price for the transaction
  • any calldata you might need to supply for calling a smart contract

As with signMessage, you will also be able to customize the text shown to your user when they are prompted to send a transaction.

Funding your users' wallet

Privy will support a default fiat on-ramp to allow your users to easily fund their embedded wallets in your app. If you prefer, you can choose to integrate an alternative fiat on-ramp with Privy's embedded wallets that may be better suited to your product needs.

Exporting private keys

Privy will also allow your user to export their full private key, if they'd like to use their embedded wallet address with another wallet client (such as MetaMask or Coinbase Wallet).