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 phone number.
- Verify the OTP sent to the user.
Please be sure to configure SMS as a login method on the Privy Developer
Dashboard under User Management > Authentication.
1. Send an OTP to the user’s phone number via SMS
After collecting and validating your users phone number, send an OTP by calling thesendCode
method.
Note: you must provide the phone number in E.164 format.
sendCode
will not throw an error.
If the provided phone number is invalid, or sending the OTP fails, sendCode
will throw an error.
2. Authenticate with OTP
The user will then receive an SMS with a 6-digit OTP. Prompt for this OTP within your application, then authenticate the user with theloginWithCode
method. Pass the following parameters to this method:
loginWithCode
will return the PrivyUser
.
If the provided OTP/phone number combination is invalid, loginWithCode
will throw an error that speicfies the error reason.
The embedded wallet
Privy’s embedded wallets are compatible with the Ethereum and Solana blockchains.Creating the embedded wallet
To create an EVM embedded wallet for your user, callPrivyUser.createEthereumWallet
.- The user is not authenticated
- If a user already has 9 or more wallets
- If the network call to create the wallet fails
- If a user already has an embedded wallet and allowAdditional is not set to true.
Example
Using the embedded wallet
To enable your app to request signatures and transactions from the embedded wallet, Privy Ethereum embedded wallets expose a provider inspired by the EIP-1193 provider standard. This allows you request signatures and transactions from the wallet via a familiar JSON-RPC API (e.g.personal_sign
).Once you have an instance of an EmbeddedEthereumWallet
, you can make RPC requests by using the provider: EmbeddedEthereumWalletProvider
hook and using its request
method. For example, wallet.provider.request(request: rpcRequest)
.EthereumRpcRequest
object that contains:- method: the name of the JSON-RPC method for the wallet to execute (e.g.
personal_sign
) - params: an array of parameters required by your specified method