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.
- Send an OTP to the user provided email address.
- 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 theSendCode
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 theloginWithCode
method. As a parameter to this method, pass an object with the following fields:
- 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 theCreateWallet
method on the PrivyUser
.- the user is not authenticated
- the user already has an embedded wallet
- wallet creation fails on the user’s device
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 theRpcRequest
class from Privy. The class follows the interface below:3. Execute the RPC request
Now, simply pass therpcRequest
you constructed to the RpcProvider
’s Request
method to execute the request:RpcResponse
, which implements the interface below:Handling errors
The provider’sRequest
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
AuthenticationException
or EmbeddedWalletException
: