This guide is for the
@privy-io/node
library. If you are looking for the deprecated
@privy-io/server-auth
library, please see the NodeJS guide.0. Prerequisites
This guide assumes that you have completed the Setup guide, to get a Privy client instance,privy
.
1. Creating a wallet
First, we will create a wallet. You will use this wallet’sid
in future calls to sign messages and send transactions.
Learn more about creating wallets.
When using the
PrivyClient
to work with the API, all errors thrown will be instances of
APIError
or PrivyAPIError
. You should catch these errors and handle them accordingly, using
the error’s status
, name
and message
.2. Signing a message
Next, we’ll sign a plaintext message with the wallet using thesignMessage
method.
Make sure to specify your wallet ID (not address) from creation in the input.
Learn more about signing messages.
3. Sending transactions
Your wallet must have some funds in order to send a transaction. You can use a testnet
faucet to test transacting on a testnet (e.g. Base Sepolia)
or send funds to the wallet on the network of your choice.
sendTransaction
method.
It will populate missing network-related values (gas limit, gas fee values, nonce, type), sign your
transaction, broadcast it to the network, and return the transaction hash to you.
In the request, make sure to specify your wallet id
from your wallet creation above, as well as
the caip2
chain ID and chainId
values for the network you want to transact on.
Also, input your recipient or smart contract address in the to
field.
Learn more about sending transactions.
4. Creating a user
To create a user for your application, you can use thecreate
method, passing in
a UserCreateRequestBody
object, which allows you to specify the linked accounts, custom metadata,
and wallets that should be associated with said user.
Learn more about creating
users, and look at our pregenerating wallets guide
for linking wallets to your users before they even sign in.
Next steps & advanced topics
- For an additional layer of security, you can choose to sign your requests with authorization keys.
- To restrict what wallets can do, you can set up policies.
- To prevent double sending the same transaction, take a look at our support for idempotency keys.
- If you want to require multiple parties to sign off before sending a transaction for a wallet, you can accomplish this through the use of quorum approvals.