Installation
Originally documented at Installation.
@privy-io/server-auth library authorizes requests and manages your application from your server.
Install the library using your package manager of choice:
Setup
Originally documented at Setup.
Prerequisites
Before you begin:- Get your Privy app ID and app secret from the Privy Dashboard
- Have a minimum Node version of 18
Instantiating the PrivyClient
Import the PrivyClient class and create an instance by passing the Privy app ID and app secret as parameters.
Quickstart
Originally documented at Quickstart.
1. Creating a wallet
Create a wallet and save itsid for future calls.
- Ethereum
- Solana
2. Signing a message
Sign a plaintext message with the wallet using thesignMessage method.
- Ethereum
- Solana
3. Sending transactions
In order to send a transaction, your wallet must have some funds to pay for gas. Use a testnet
faucet to test on a testnet like Base Sepolia.
sendTransaction method to populate missing network-related values, sign, broadcast, and return the transaction hash.
- Ethereum
- Solana
Verify access tokens
Originally documented at Access tokens.
string to the PrivyClient’s verifyAuthToken method:
Create or import a user
Originally documented at Create or import a
user.
PrivyClient’s importUser method to create or import a single user.
Parameters
LinkedAccount[]
required
An array of the user’s linked accounts.
object
Custom metadata to associate with the user.
WalletCreateRequestType[]
An array of wallets to create for the user.
Query users
Originally documented at Querying users.
Query by identity token (recommended)
Query by Privy DID
Get all users
Query by account data
By email address
By email address
By phone number
By phone number
By wallet address
By wallet address
By custom auth ID
By custom auth ID
By Farcaster fid
By Farcaster fid
By Twitter subject
By Twitter subject
By Twitter username
By Twitter username
By Discord username
By Discord username
By Telegram user ID
By Telegram user ID
By Telegram username
By Telegram username
Delete a user
Originally documented at Deleting users.
PrivyClient’s deleteUser method to delete a user. Pass the user’s Privy DID as a string:
Custom metadata
Originally documented at Custom metadata.
PrivyClient’s setCustomMetadata method to set custom metadata for a user by their DID.
Allowlist
Originally documented at Allowlist.
Add to allowlist
Use theinviteToAllowlist method to add a user to your allowlist.
'email' | 'phone' | 'wallet'
required
The type of account to add to the allowlist.
string
required
The identifier of the account to add to the allowlist.
Remove from allowlist
Use theremoveFromAllowlist method to remove a user from your allowlist.
Get allowlist
Use thegetAllowlist method to get your app’s current allowlist.
Test accounts
Originally documented at Using test accounts.
getTestAccessToken method to get an access token for a test account.
Create a wallet
Originally documented at Create a wallet.
createWallet method from the Privy client’s walletApi class:
Usage
Parameters
'ethereum' | 'solana' | 'stellar' | 'cosmos' | 'sui' | 'tron' | 'bitcoin-segwit' | 'near' | 'ton' | 'starknet' | 'aptos'
required
Chain type of the wallet to create.
{'userId': string} | {'publicKey': string}
The user ID or P-256 public key to set as the owner. Do not specify
ownerId if providing this.string
The key quorum ID of the owner. Do not specify
owner if providing this.string[]
List of policy IDs to enforce on the wallet.
string
Idempotency key to identify a unique request.
{'signerId': string}[]
List of key quorum IDs allowed to approve transactions for the wallet.
Returns
string
Unique ID of the created wallet.
string
Address of the created wallet.
string
Chain type of the created wallet.
Get wallet by ID
Originally documented at Get wallet by ID.
Usage
Parameters
string
The ID of the wallet to get.
Returns
WalletApiWalletResponseType
Get all wallets
Originally documented at Get all wallets.
walletApi.getWallets method. This is a paginated query.
Usage
Import a wallet (private key)
Originally documented at Import a wallet (private
key).
importWallet method from the Privy client’s walletApi class.
- EVM
- Solana
The Privy client accepts a hex-encoded private key, with or without a
0x prefix.Import an HD wallet
Originally documented at HD wallets.
importWallet method from the Privy client’s walletApi class.
- Ethereum
- Solana
Sign a message (Ethereum)
Originally documented at Sign a message.
signMessage method on the Ethereum client.
Usage
Parameters
string
required
Unique ID of the wallet.
string | Uint8Array
required
The string or bytes to sign.
string
Returns
string
The signature produced by the wallet.
'hex'
The encoding format for the signature.
Sign typed data (EIP-712)
Originally documented at Sign typed data.
signTypedData method on the Ethereum client.
Usage
Sign a transaction (Ethereum)
Originally documented at Sign a transaction.
signTransaction method on the Ethereum client.
Usage
Parameters
string
required
The ID of the wallet.
EthereumTransactionType
required
The transaction to sign.
Returns
string
The signed transaction.
'rlp'
The encoding format. Only
'rlp' is supported.Sign a raw hash
Originally documented at Sign a raw hash.
secp256k1Sign method on the Ethereum client.
Usage
Parameters
string
required
Unique ID of the wallet.
hash
required
The hash to sign. Must start with
0x.Sign EIP-7702 authorization
Originally documented at Sign EIP-7702
authorization.
sign7702Authorization method on the Ethereum client.
Usage
Parameters
string
required
Unique ID of the wallet.
Hex
required
The smart contract address to delegate to.
number
required
The chain ID for the authorization.
number
The nonce for the authorization. Defaults to the current transaction count.
string
Send a transaction (Ethereum)
Originally documented at Send a transaction.
sendTransaction method on the Ethereum client.
Usage
Parameters
string
required
The ID of the wallet.
`eip155:${number}`
required
The CAIP2 chain ID.
EthereumTransactionType
required
The transaction to send.
boolean
Enable gas sponsorship. Learn more.
Returns
string
The transaction hash.
`eip155:${number}`
The CAIP2 chain ID.
Web3 integrations (Ethereum)
Originally documented at Interfacing with common
libraries.
viem
Use Privy’screateViemAccount method to initialize a viem Account for an EVM wallet.
Account, initialize a viem WalletClient:
ethers
Use Privy’screateEthersSigner method to initialize an ethers signer.
Sign a message (Solana)
Originally documented at Sign a message (Solana).
signMessage method on the Solana client.
Usage
Parameters
string
required
Unique ID of the wallet.
string | Uint8Array
required
The string or bytes to sign.
string
Sign a transaction (Solana)
Originally documented at Sign a transaction
(Solana).
signTransaction method on the Solana client.
Usage
Parameters
string
required
The ID of the wallet.
Transaction | VersionedTransaction
required
The transaction to sign.
Returns
string
The signed transaction.
'base64'
The encoding format. Only
'base64' is supported.Send a transaction (Solana)
Originally documented at Send a transaction
(Solana).
signAndSendTransaction method on the Solana client.
Usage
Parameters
string
required
The ID of the wallet.
string
required
The CAIP2 chain ID.
Transaction | VersionedTransaction
required
The transaction to sign and send.
boolean
Enable gas sponsorship.
Returns
string
The transaction hash.
string
The CAIP2 chain ID.
Send SOL
Originally documented at Sending a SOL transaction.
Send SPL tokens
Originally documented at Sending SPL tokens.
Send USDC (ERC-20)
Originally documented at Sending USDC.
Create a policy
Originally documented at Create a policy.
PrivyClient’s createPolicy method.
Get a policy
Originally documented at Get a policy.
PrivyClient’s getPolicy method.
Update a policy
Originally documented at Update a policy.
Add a rule to a policy
Edit a rule in a policy
Delete a rule from a policy
Update a whole policy
Request a user authorization key
Originally documented at Using user owners &
signers.
1. Request a user key
Use thegenerateUserSigner method of the Privy client.
string
required
The user’s JWT to authenticate the user.
2. Update the Privy client to use the user’s keypair
3. Execute requests with the user’s authorization key
Once updated, the Privy client automatically signs requests made viaprivy.walletApi.ethereum.* and privy.walletApi.solana.* methods.
Use signers
Originally documented at Use signers.
getUser method to get a user object. Pass the user’s identity token:
Using user signers
Originally documented at Using user signers.
- Generate a SPKI-formatted ECDH P-256 keypair.
- Request a time-bound session key from
/v1/wallets/authenticateusing the user’s JWT and the public key. - Send a transaction to the Wallet API, signed with the session key.
Generate an ECDH P-256 keypair
POST /v1/wallets/authenticate
Decrypt the response
Send a transaction using the decrypted key
Sponsor gas on Ethereum
Originally documented at Sponsoring transactions on
Ethereum.
0. Install dependencies
1. Create a wallet
2. Get a viem LocalAccount
3. Create a smart wallet
4. Create a smart account client
Fetch a transaction
Originally documented at Fetch transaction via
API.
getTransaction method from the Privy client.
Parameters
string
required
ID of the transaction to fetch.
Pregenerate wallets
Originally documented at Pregenerating wallets.
importUser method.
Server-side user wallets
Originally documented at Server-side user wallets.
importUser method to create a user.
Verify access token (optimizing)
Originally documented at Optimize your setup.
Idempotency keys
Originally documented at Idempotency keys.
tRPC integration
Originally documented at Integrating with tRPC.
Speeding up transactions
Originally documented at Speeding up transactions on EVM
chains.
Telegram bot
Originally documented at Building a Telegram trading bot.
Initialize the client
Send a transaction on command
Bot-first wallet creation
Flashblocks
Originally documented at Using Flashblocks with Privy.
@privy-io/server-auth SDK and broadcast to your custom Flashblocks RPC URL:
Aave integration
Originally documented at Integrating Aave with Privy.
Installation
Setup
Signing utility functions
Originally documented at Signing with utility
functions.

