Skip to main content

Prerequisites

This guide assumes that you have completed the setup guide.

Check user’s authentication state

Authenticate your user

This quickstart guide will demonstrate how to authenticate a user with a one time password as an example, but Privy supports many authentication methods. Explore our Authentication docs to learn about other methods such as socials, passkeys, and external wallets to authenticate users in your app.
Privy offers a variety of authentication mechanisms. The example below showcases authenticating a user via email. This is a two step process:
  1. Send an OTP to the user provided email address.
  2. Verify the OTP sent to the user.

1. Send an OTP to the user’s email address

After collecting and validating your users email, send an OTP by calling the SendCode method.

2. Authenticate with OTP

The user will then receive an email with a 6-digit OTP. Prompt the user for this OTP within your application, then authenticate the user with the loginWithCode method. As a parameter to this method, pass an object with the following fields:
This method will throw an error if:
  • the incorrect OTP code is inputted
  • the network call to authenticate the user fails

The embedded wallet

Create an embedded wallet

To create an embedded Ethereum wallet for your user, call the CreateEthereumWallet method on IPrivyUser.
This method will throw an error if:
  • the user is not authenticated
  • the user already has an embedded wallet
  • wallet creation fails on the user’s device
To use embedded wallets, Privy implements an RpcProvider on the EmbeddedWallet class of the Unity SDK. This is an EIP1193 provider is responsible for managing RPC requests to a user’s embedded wallet.Currently, Privy’s RpcProvider only supports the personal_sign and eth_signTypedData_v4 RPCs. We are actively adding support for other methods.

1. Get the user’s wallet

To make an RPC request to a user’s wallet, first get the user’s embedded wallet like so:

2. Construct your RPC request

Next, construct the RPC request using the RpcRequest class from Privy. The class follows the interface below:
As an example, you can construct a new RPC request like so.

3. Execute the RPC request

Now, simply pass the rpcRequest you constructed to the RpcProvider’s Request method to execute the request:
This will return an RpcResponse, which implements the interface below:

Handling errors

The provider’s Request method may error if:
  • the user is not authenticated
  • the user’s wallet does not exist or has not loaded on their device
  • there is an issue with the RPC request that was sent to the wallet
These errors can be caught through a generic exception, or Privy’s custom PrivyAuthenticationException or PrivyWalletException:

Full example

As a complete example, you can send an RPC request to a wallet and handle corresponding errors like so: