Skip to content

TypeScript SDK Quickstart

You can use Privy's server wallets through either our TypeScript SDK or REST API.

INFO

Before getting started, request access to server wallets from the plugins page of the Privy Dashboard

Using Privy's TypeScript SDK

0. Prerequisites

  • Set up a Privy app and retrieve your App ID and App secret

  • Set up a NodeJS TypeScript environment

sh
npm init
npm install -D typescript tsx
npx tsc --init
  • Install Privy’s server-auth package
sh
npm i @privy-io/server-auth
  • Create an index.ts file which we'll use to make requests to server wallets

  • To run your application, run:

sh
npx tsx index.ts

1. Initialize your Privy client

Initialize your Privy client using your App ID and App secret from the Privy Dashboard.

tsx
import {PrivyClient} from '@privy-io/server-auth';

const privy = new PrivyClient('insert_your_privy_app_id', 'insert_your_privy_app_secret');

2. Creating a wallet

First, we’ll create a server wallet. You’ll use this wallet’s id in future calls to sign messages and send transactions.

tsx
const {id, address, chainType} = await privy.walletApi.create({chainType: 'ethereum'});

3. Signing a message

Next, we’ll sign a plaintext message with the server wallet using the signMessage method. Make sure to specify your wallet ID (not address) from creation in the input.

tsx
const {data} = await privy.walletApi.ethereum.signMessage({
  walletId: id,
  message: 'Hello server wallets!',
});

const {signature, encoding} = data;

TIP

For Solana, use the solana.signMessage method.

4. Send some funds to your server wallet

In order to send a transaction, your wallet must have some funds to pay for gas. 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.

5. Sending transactions

To send a transaction from your wallet, use the 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.

The example below sends a transaction on the Base Sepolia testnet.

tsx
const {data} = await privy.walletApi.ethereum.sendTransaction({
  walletId: id,
  caip2: 'eip155:84532',
  transaction: {
    to: '0xyourRecipientAddress',
    value: 100000,
    chainId: 84532,
  },
});

const {hash} = data;

TIP

For Solana, use the signAndSendTransaction method.

TIP

If you’re interested in more control, you can prepare and broadcast the transaction yourself, and simply use eth_signTransaction (EVM) and signTransaction (Solana) RPCs to sign the transaction with a server wallet.

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.