Appearance
Using wallets on EVM networks
You can use Privy server wallets to sign messages and execute transactions on any EVM-compatible network, like Ethereum, Base, or Arbitrum.
Using the SDK
To execute an EVM action with a server wallet, use the PrivyClient
's walletApi.rpc
method. As a parameter to this method, pass the request to execute with the wallet.
tsx
const {data} = await privy.walletApi.rpc({
walletId: 'insert-wallet-id',
method: 'eth_sendTransaction',
caip2: 'eip155:8453',
params: {
transaction: {
to: '0xE3070d3e4309afA3bC9a6b057685743CF42da77C',
value: 100000,
chainId: 8453,
},
},
});
const hash = data.hash;
There are currently four supported EVM actions: personal_sign
, eth_signTypedData_v4
, eth_signTransaction
, and eth_sendTransaction
.
The request
should be an object with one of the following sets of parameters:
Field | Type | Description |
---|---|---|
walletId | string | Unique ID of the wallet to take actions with. |
idempotencyKey | string | (Optional) Idempotency key to identify a unique request. |
method | 'personal_sign' | RPC method to execute with the wallet. |
params | Object | Parameters for the RPC method to execute with the wallet. |
params.message | string | Uint8Array | The string or bytes to sign with the wallet. |
Using the REST API
To request a signature or transaction from an Ethereum wallet, make a POST
request to:
sh
https://api.privy.io/v1/wallets/<wallet_id>/rpc
TIP
In the request headers, make sure to include Privy's required authentication headers and headers that may be required for your app's wallet API setup.
Body
In the body of the request, include the following fields. Make sure to follow the appropriate guidance for the action you'd like to take with the wallet (signing messages, signing typed data, signing transactions, or signing and broadcasting transactions).
Field | Type | Description |
---|---|---|
method | 'personal_sign' | RPC method to execute with the wallet. |
params | Object | Parameters for the RPC method to execute with the wallet. |
params.message | string | The 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:
Field | Type | Description |
---|---|---|
method | 'personal_sign' | The RPC method executed with the wallet. |
data | Object | Outputs for the RPC method executed with the wallet. |
data.signature | string | An 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://api.privy.io/v1/wallets/<wallet_id>/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 '{
"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"
}
}