Skip to main content
The @privy-io/server-auth library is deprecated. This page compiles legacy documentation for existing customers who have not yet migrated. For new integrations, refer to the @privy-io/node guide. For migration instructions, see the migration guide.

Installation

Originally documented at Installation.
In a backend JS environment, the @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:

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 its id for future calls.

2. Signing a message

Sign a plaintext message with the wallet using the signMessage method.

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.
Use the sendTransaction method to populate missing network-related values, sign, broadcast, and return the transaction hash.

Verify access tokens

Originally documented at Access tokens.
Pass the user’s access token as a string to the PrivyClient’s verifyAuthToken method:
To avoid a network request on each verification, pass the verification key directly:

Create or import a user

Originally documented at Create or import a user.
Use the 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 Privy DID

Get all users

Query by account data


Delete a user

Originally documented at Deleting users.
Use the PrivyClient’s deleteUser method to delete a user. Pass the user’s Privy DID as a string:
This method throws an error if the deletion fails (e.g. due to an invalid Privy DID).

Custom metadata

Originally documented at Custom metadata.
Use the PrivyClient’s setCustomMetadata method to set custom metadata for a user by their DID.
When using TypeScript, specify a type generic to enable type inference:

Allowlist

Originally documented at Allowlist.

Add to allowlist

Use the inviteToAllowlist 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 the removeFromAllowlist method to remove a user from your allowlist.

Get allowlist

Use the getAllowlist method to get your app’s current allowlist.

Test accounts

Originally documented at Using test accounts.
Enabling a test account registers a set of test credentials (a hardcoded email or phone number and OTP code); it does not create a Privy user record. The user record is created on the first successful login. Use the getTestAccessToken method to get an access token for a test account.

Create a wallet

Originally documented at Create a wallet.
Use the 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.
Use the Privy client’s walletApi.getWallets method. This is a paginated query.

Usage


Import a wallet (private key)

Originally documented at Import a wallet (private key).
Use the importWallet method from the Privy client’s walletApi class.
The Privy client accepts a hex-encoded private key, with or without a 0x prefix.

Import an HD wallet

Originally documented at HD wallets.
Use the importWallet method from the Privy client’s walletApi class.

Sign a message (Ethereum)

Originally documented at Sign a message.
Use the 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.
Use the signTypedData method on the Ethereum client.

Usage


Sign a transaction (Ethereum)

Originally documented at Sign a transaction.
Use the 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.
Use the 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.
Use the 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.
Use the 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’s createViemAccount method to initialize a viem Account for an EVM wallet.
From the returned Account, initialize a viem WalletClient:

ethers

Use Privy’s createEthersSigner method to initialize an ethers signer.

Sign a message (Solana)

Originally documented at Sign a message (Solana).
Use the 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).
Use the 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).
Use the 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.
Use the PrivyClient’s createPolicy method.

Get a policy

Originally documented at Get a policy.
Use the 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 the generateUserSigner 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 via privy.walletApi.ethereum.* and privy.walletApi.solana.* methods.

Use signers

Originally documented at Use signers.
Use the Privy client’s getUser method to get a user object. Pass the user’s identity token:
Filter for wallets with signers:

Using user signers

Originally documented at Using user signers.
Once you have created a wallet with a user signer, your application will:
  1. Generate a SPKI-formatted ECDH P-256 keypair.
  2. Request a time-bound session key from /v1/wallets/authenticate using the user’s JWT and the public key.
  3. 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


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.
Use the getTransaction method from the Privy client.

Parameters

string
required
ID of the transaction to fetch.

Pregenerate wallets

Originally documented at Pregenerating wallets.
To pregenerate wallets for a new user, use the importUser method.

Server-side user wallets

Originally documented at Server-side user wallets.
Use the Privy client’s importUser method to create a user.

Verify access token (optimizing)

Originally documented at Optimize your setup.
To avoid a network call when verifying access tokens, pass the verification key directly:

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.
Send a replacement transaction using the same nonce:

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.
Sign a transaction with the @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.

Format a request for an authorization signature