Skip to content

Taking actions on EVM networks

Once a user has consented to delegated actions for their wallet, your app can take certain actions with the user's wallet.

Using @privy-io/server-auth

To execute an EVM RPC request with a delegated wallet, use the PrivyClient's walletApi.rpc method. As a parameter to this method, pass the request to execute with the wallet.

tsx
const request = {
  address: '0xb8B849D7647937eB7331Dc7b6C445651A3EC55aE',
  chainType: 'ethereum',
  method: 'eth_signTransaction',
  params: {
    transaction: {
      to: '0xE3070d3e4309afA3bC9a6b057685743CF42da77C',
      value: 100000,
    },
  },
};

const {data} = await privy.walletApi.rpc(request); 
const signedTransaction = data.signedTransaction; 

There are currently three supported EVM actions: personal_sign, eth_signTypedData_v4, and eth_signTransaction.

The request should be an object with one of the following sets of parameters:

FieldTypeDescription
addressstringAddress of the wallet to take actions with.
chainType'ethereum'Chain type of the wallet to take actions with.
method'personal_sign'RPC method to execute with the wallet.
paramsObjectParameters for the RPC method to execute with the wallet.
params.messagestring | Uint8ArrayThe string or bytes to sign with the wallet.

Using the REST API

To execute an EVM RPC request with a delegated wallet, make a POST request to:

bash
https://auth.privy.io/api/v1/wallets/rpc

Body

In the body of the request, include the following:

FieldTypeDescription
addressstringAddress of the wallet to take actions with.
chain_type'ethereum'Chain type of the wallet to take actions with.
method'personal_sign'RPC method to execute with the wallet.
paramsObjectParameters for the RPC method to execute with the wallet.
params.messagestringThe message to sign with the wallet. If the message to sign is raw bytes, you must serialize the message as a hexadecimal string.
params.encoding'utf-8' | 'hex'The encoding format for params.message. Use utf-8 for a string message and hex for bytes.

Response

If the action is allowed, Privy will send the following fields in the response body:

FieldTypeDescription
method'personal_sign'The RPC method executed with the wallet.
dataObjectOutputs for the RPC method executed with the wallet.
data.signaturestringAn encoded string serializing the signature produced by the user's wallet.
data.encoding'hex'The encoding format for the returned signature. Currently, only 'hex' is supported for Ethereum.

Examples

As an example, a sample request to take a delegated action with a wallet might look like the following:

bash
$ curl --request POST https://auth.privy.io/api/v1/wallets/rpc \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "privy-authorization-signature: <authorization-signature-for-request>" \
-H 'Content-Type: application/json' \
-d '{
  "address": "0xb8B849D7647937eB7331Dc7b6C445651A3EC55aE",
  "chain_type": "ethereum",
  "method": "personal_sign",
  "params": {
    "message": "Hello, Ethereum.",
    "encoding": "utf-8"
  }
}'

A successful response will look like the following:

json
{
  "method": "personal_sign",
  "data": {
    "signature": "0x28eac519bf4051a624d4246a5788667baf84dcd7d2a439b314b339013b5cdb4c",
    "encoding": "hex"
  }
}