Learn how to authenticate users, create embedded wallets, and send transactions in your Android app
This guide assumes that you have completed the setup guide.
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 SMS.
This is a two step process:
Please be sure to configure SMS as a login method on the Privy Developer Dashboard under User Management > Authentication.
After collecting and validating your users phone number, send an OTP by calling the sendCode
method.
Note: you must provide the phone number in E.164 format.
If the OTP is sent successfully, sendCode
will return Result.success
with no associated type.
If the provided phone number is invalid, or sending the OTP fails, sendCode
will return Result.failure
.
The user will then receive an SMS with a 6-digit OTP. Prompt for this OTP within your application, then authenticate the user with the loginWithCode
method. Pass the following parameters to this method:
If the OTP/phone number combination is valid, Privy will successfully authenticate your user and loginWithCode
will return Result.success
with an encapsulated PrivyUser
.
If the provided OTP/phone number combination is invalid, loginWithCode
will return Result.failure
.
To create an EVM embedded wallet for your user, call the createEthereumWallet
method on your PrivyUser
instance.
If a wallet is successfully created for the user, an EmbeddedEthereumWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
allowAdditional
is not set to true.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)
. This request method will suspend and await if the embedded wallet needs to wait for any internal ready state.
As a parameter to this method, to this method, pass an 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
By default, embedded wallets are connected to the Ethereum mainnet. To send a transaction on a different network, simply set the wallet’s chainId
in the transaction request.
Example usage:
To create an EVM embedded wallet for your user, call the createEthereumWallet
method on your PrivyUser
instance.
If a wallet is successfully created for the user, an EmbeddedEthereumWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
allowAdditional
is not set to true.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)
. This request method will suspend and await if the embedded wallet needs to wait for any internal ready state.
As a parameter to this method, to this method, pass an 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
By default, embedded wallets are connected to the Ethereum mainnet. To send a transaction on a different network, simply set the wallet’s chainId
in the transaction request.
Example usage:
To create a Solana embedded wallet for your user, call the createSolanaWallet
method on your PrivyUser
instance.
If a wallet is successfully created for the user, an EmbeddedSolanaWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
Privy supports requesting signatures on messages and transactions from a user’s Solana embedded wallet using the signMessage
RPC. To request a signature, get the Solana embedded wallet provider and call the signMessage
method on it with a base-64 encoded message to sign. If the signature is computed successfully, signMessage
will return it as a base64-encoded string.
Example usage:
Learn how to authenticate users, create embedded wallets, and send transactions in your Android app
This guide assumes that you have completed the setup guide.
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 SMS.
This is a two step process:
Please be sure to configure SMS as a login method on the Privy Developer Dashboard under User Management > Authentication.
After collecting and validating your users phone number, send an OTP by calling the sendCode
method.
Note: you must provide the phone number in E.164 format.
If the OTP is sent successfully, sendCode
will return Result.success
with no associated type.
If the provided phone number is invalid, or sending the OTP fails, sendCode
will return Result.failure
.
The user will then receive an SMS with a 6-digit OTP. Prompt for this OTP within your application, then authenticate the user with the loginWithCode
method. Pass the following parameters to this method:
If the OTP/phone number combination is valid, Privy will successfully authenticate your user and loginWithCode
will return Result.success
with an encapsulated PrivyUser
.
If the provided OTP/phone number combination is invalid, loginWithCode
will return Result.failure
.
To create an EVM embedded wallet for your user, call the createEthereumWallet
method on your PrivyUser
instance.
If a wallet is successfully created for the user, an EmbeddedEthereumWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
allowAdditional
is not set to true.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)
. This request method will suspend and await if the embedded wallet needs to wait for any internal ready state.
As a parameter to this method, to this method, pass an 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
By default, embedded wallets are connected to the Ethereum mainnet. To send a transaction on a different network, simply set the wallet’s chainId
in the transaction request.
Example usage:
To create an EVM embedded wallet for your user, call the createEthereumWallet
method on your PrivyUser
instance.
If a wallet is successfully created for the user, an EmbeddedEthereumWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
allowAdditional
is not set to true.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)
. This request method will suspend and await if the embedded wallet needs to wait for any internal ready state.
As a parameter to this method, to this method, pass an 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
By default, embedded wallets are connected to the Ethereum mainnet. To send a transaction on a different network, simply set the wallet’s chainId
in the transaction request.
Example usage:
To create a Solana embedded wallet for your user, call the createSolanaWallet
method on your PrivyUser
instance.
If a wallet is successfully created for the user, an EmbeddedSolanaWallet
object is returned as an encapsulated value of Result.success.
This method will Result.failure
if:
Privy supports requesting signatures on messages and transactions from a user’s Solana embedded wallet using the signMessage
RPC. To request a signature, get the Solana embedded wallet provider and call the signMessage
method on it with a base-64 encoded message to sign. If the signature is computed successfully, signMessage
will return it as a base64-encoded string.
Example usage: