Quickstart
Learn how to authenticate users, create embedded wallets, and send transactions in your Unity app
Prerequisites
This guide assumes that you have completed the setup guide.
Authenticate your user
Privy offers a variety of authentication mechanisms. The example below showcases authenticating a user via email.
This is a two step process:
- 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 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
Privy’s embedded wallets are currently only compatible with the Ethereum blockchains.
To create an embedded wallet for your user, call the CreateWallet
method on the PrivyUser
.
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 AuthenticationException
or EmbeddedWalletException
:
Full example
As a complete example, you can send an RPC request to a wallet and handle corresponding errors like so:
Was this page helpful?