When using Privy’s server-side SDKs to sign transactions, you can use the authorization context to
automatically sign requests. Learn more about signing on the
server.
- React
- React Native
- Swift
- Android
- Unity
- Flutter
- NodeJS
- NodeJS (server-auth)
- Java
- Rust
- REST API
To send a transaction from a wallet using the React SDK, use the
signTransaction method from the useSignTransaction hook:Report incorrect code
Copy
Ask AI
signTransaction: (input: UnsignedTransactionRequest, options?: SendTransactionOptions) => Promise<{ signature: HexString }>
Usage
Report incorrect code
Copy
Ask AI
import {useSignTransaction, useWallets} from '@privy-io/react-auth';
const {signTransaction} = useSignTransaction();
const {wallets} = useWallets();
signTransaction(
{
to: '0xE3070d3e4309afA3bC9a6b057685743CF42da77C',
value: 100000
},
{
address: wallets[0].address // Optional: Specify the wallet to use for signing. If not provided, the first wallet will be used.
}
);
Parameters
The details of the transaction to sign.
The options for the UI of the send transaction modal. Learn
more.
To hide confirmation modals, set
options.uiOptions.showWalletUIs to false. Learn more about
configuring modal prompts here.The configuration for funding the wallet.
The address of the wallet to use for signing the transaction. Recommended when working with
external wallets to ensure reliable functionality. If not provided, the first wallet will be
used.
Returns
The signed transaction hash.
To sign a transaction from a wallet using the React Native SDK use the
request method from the wallets EIP1193 provider:Report incorrect code
Copy
Ask AI
request: (request: { method: 'eth_signTransaction', params: [SignTransactionParams] }) => Promise<HexString>
The Expo SDK does not support built-in UIs for sending transactions.
The
eth_signTransaction method gives you complete control over the experience and UI.Usage
Report incorrect code
Copy
Ask AI
import {useEmbeddedEthereumWallet} from '@privy-io/expo';
const {wallets} = useEmbeddedEthereumWallet();
const wallet = wallets[0];
const provider = await wallet.getProvider();
const accounts = await provider.request({
method: 'eth_requestAccounts',
});
// Sign transaction (will be signed and populated)
const response = await provider.request({
method: 'eth_signTransaction',
params: [
{
from: accounts[0],
to: '0x0000000000000000000000000000000000000000',
value: '1',
},
],
});
Parameters
The RPC method executed with the wallet.
The details of the transaction to sign.
Returns
The hash for the broadcasted transaction.
Use the
request method on the Ethereum provider to sign a transaction with an Ethereum wallet.Report incorrect code
Copy
Ask AI
func request(_ request: EthereumRpcRequest) async throws -> String
Usage
Report incorrect code
Copy
Ask AI
let provider = wallet.provider
let transaction = EthereumRpcRequest.UnsignedEthTransaction(
from: wallet.address,
to: "0xE3070d3e4309afA3bC9a6b057685743CF42da77C",
value: .int(100000),
chainId: .hexadecimal("0x2105"), // Base, in hex
)
let transactionSignature = try await provider.request(.ethSignTransaction(transaction: transaction))
Parameters
The transaction to send.
Hide child attributes
Hide child attributes
The address sending the transaction (the user’s wallet address).
The address to send the transaction to.
The amount of wei to send, as an integer or hexadecimal string.
The chain ID as an integer or hexadecimal string. Defaults to mainnet (0x1) if omitted.
The data to include with the transaction, as a hexadecimal string.
The gas limit for the transaction, as a hexadecimal string.
Returns
The signature of the transaction.
Use the
request method on the Ethereum wallet provider to sign a transaction with an Ethereum wallet.Report incorrect code
Copy
Ask AI
public suspend fun request(request: EthereumRpcRequest): Result<EthereumRpcResponse>
Usage
Report incorrect code
Copy
Ask AI
val transaction = JSONObject().apply {
put("to", "0xE3070d3e4309afA3bC9a6b057685743CF42da77C")
put("value", "0x186a0") // 100000 in hex
put("chainId", "0x2105") // 8453 (Base) in hex
put("from", ethereumWallet.address)
}.toString()
val result = ethereumWallet.provider.request(
request = EthereumRpcRequest.ethSignTransaction(transaction),
)
when (result) {
is Result.Success -> {
val transactionHash = result.data.data
// Handle successful transaction
}
is Result.Failure -> {
// Handle error
}
}
Parameters
The RPC method to execute with the wallet.
Array containing the transaction JSON as a single string element.
Hide child attributes
Hide child attributes
The address to send the transaction to.
The amount of wei to send, as a hexadecimal string.
The chain ID as a hexadecimal string. Defaults to mainnet (0x1) if omitted.
The address sending the transaction (the user’s wallet address).
The data to include with the transaction, as a hexadecimal string.
The gas limit for the transaction, as a hexadecimal string.
Returns
Use the
Request method on the wallet’s RPC provider to sign a transaction with an Ethereum wallet.Report incorrect code
Copy
Ask AI
public Task<RpcResponse> Request(RpcRequest request);
Usage
Report incorrect code
Copy
Ask AI
// Create transaction JSON
string transactionJson = JsonUtility.ToJson(new {
to = "0xE3070d3e4309afA3bC9a6b057685743CF42da77C",
value = "0x186a0", // 100000 in hex
chainId = "0x2105", // 8453 (Base) in hex
from = embeddedWallet.Address
});
// Create RPC request
var rpcRequest = new RpcRequest
{
Method = "eth_signTransaction",
Params = new string[] { transactionJson }
};
// Sign transaction
RpcResponse transactionResponse = await embeddedWallet.RpcProvider.Request(rpcRequest);
// Transaction hash is in the response data
string transactionHash = transactionResponse.Data;
Parameters
The RPC method to execute with the wallet.
Array containing the transaction JSON as a single string element.
Hide child attributes
Hide child attributes
The address to send the transaction to.
The amount of wei to send, as a hexadecimal string.
The chain ID as a hexadecimal string. Defaults to mainnet (0x1) if omitted.
The address sending the transaction (the user’s wallet address).
The data to include with the transaction, as a hexadecimal string.
The gas limit for the transaction, as a hexadecimal string.
Returns
Use the
request method on the Ethereum wallet provider to sign a transaction with an Ethereum wallet.Report incorrect code
Copy
Ask AI
Future<Result<EthereumRpcResponse>> request(EthereumRpcRequest request);
Usage
Report incorrect code
Copy
Ask AI
// Create transaction parameters as a Map
final transactionMap = {
'to': '0xE3070d3e4309afA3bC9a6b057685743CF42da77C',
'value': '0x186a0', // 100000 in hex
'chainId': '0x2105', // 8453 (Base) in hex
'from': ethereumWallet.address
};
// Convert Map to JSON string
final transactionJson = jsonEncode(transactionMap);
// Create the RPC request
final rpcRequest = EthereumRpcRequest(
method: 'eth_signTransaction',
params: [transactionJson],
);
// Sign the transaction
final result = await ethereumWallet.provider.request(rpcRequest);
// Handle the result
result.when(
success: (response) {
final transactionHash = response.data;
print('Transaction sent with hash: $transactionHash');
},
failure: (error) {
print('Failed to sign transaction: $error');
},
);
Parameters
The RPC method to execute with the wallet.
List containing the transaction JSON as a single string element.
Hide child attributes
Hide child attributes
The address to send the transaction to.
The amount of wei to send, as a hexadecimal string.
The chain ID as a hexadecimal string. Defaults to mainnet (0x1) if omitted.
The address sending the transaction (the user’s wallet address).
The data to include with the transaction, as a hexadecimal string.
The gas limit for the transaction, as a hexadecimal string.
Returns
Use the
signTransaction method on the Ethereum interface to sign a transaction with an Ethereum wallet.Usage
Report incorrect code
Copy
Ask AI
const {signed_transaction, encoding} = await privy.wallets().ethereum().signTransaction('insert-wallet-id', {
params: {
transaction: {
to: '0xE3070d3e4309afA3bC9a6b057685743CF42da77C',
value: '0x2386F26FC10000',
chain_id: 8453,
},
}
});
Parameters and Returns
Check out the API reference for more details.The
@privy-io/server-auth library is deprecated. We recommend integrating @privy-io/node for
the latest features and support.Use the
signTransaction method on the Ethereum client to sign a transaction with an Ethereum wallet.Report incorrect code
Copy
Ask AI
signTransaction: (input: EthereumSignTransactionInputType) => Promise<EthereumSignTransactionResponseType>
Usage
Report incorrect code
Copy
Ask AI
const {signedTransaction, encoding} = await privy.walletApi.ethereum.signTransaction({
walletId: 'insert-wallet-id',
transaction: {
to: '0xE3070d3e4309afA3bC9a6b057685743CF42da77C',
value: '0x2386F26FC10000',
chainId: 8453,
},
});
Parameters
The ID of the wallet to sign the transaction with.
The transaction to sign.
Returns
The signed transaction.
The encoding format for the returned
signedTransaction. Currently, only 'rlp' is supported for Ethereum.To sign a transaction from your wallet, use the
signTransaction method.
It will sign your transaction, and return the signed transaction to you.Usage
Report incorrect code
Copy
Ask AI
try {
EthereumSignTransactionRpcInputTransaction txn = EthereumSignTransactionRpcInputTransaction.builder()
.to(recipientAddress)
.value(EthereumSignTransactionRpcInputValue.of("0x1")) // 1 wei
.chainId(EthereumSignTransactionRpcInputChainId.of(11_155_111)) // Sepolia testnet
.build();
// Example: If wallet's owner is an authorization private key
AuthorizationContext authorizationContext = AuthorizationContext.builder()
.addAuthorizationPrivateKey("authorization-key")
.build();
EthereumSignTransactionRpcResponseData response = privyClient
.wallets()
.ethereum()
.signTransaction(
walletId,
txn,
authorizationContext
);
String signedTransaction = response.signedTransaction();
} catch (APIException e) {
String errorBody = e.bodyAsString();
System.err.println(errorBody);
} catch (Exception e) {
System.err.println(e.getMessage());
}
Parameters
When defining a transaction, you may specify the following values on theEthereumSignTransactionRpcInputTransaction builder:The address sending the transaction (the user’s wallet address).
The address to send the transaction to.
The ID of the chain the transaction is being sent on.
The nonce for the transaction.
The data to include with the transaction, as a hexadecimal string.
The amount of wei to send, as an integer or hexadecimal string.
The type of transaction to send.
The gas limit for the transaction, as a hexadecimal string.
The gas price for the transaction, as a hexadecimal string.
The maximum fee per gas for the transaction, as a hexadecimal string.
The maximum priority fee per gas for the transaction, as a hexadecimal string.
Returns
TheEthereumSignTransactionRpcResponseData object contains a signedTransaction() fieldThe signed transaction.
Use the
sign_transaction method on the Ethereum service to sign a transaction with an Ethereum wallet.Usage
Report incorrect code
Copy
Ask AI
use privy_rs::{AuthorizationContext, PrivyClient};
let client = PrivyClient::new("app_id".to_string(), "app_secret".to_string())?;
let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();
let transaction = EthereumSignTransactionRpcInputParamsTransaction {
to: Some("0x742d35Cc6635C0532925a3b8c17d6d1E9C2F7ca".to_string()),
value: None,
gas_limit: None,
gas_price: None,
nonce: None,
chain_id: None,
data: None,
from: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
type_: None,
};
let signed_tx = ethereum_service
.sign_transaction(&wallet_id, transaction, &auth_ctx, None)
.await?;
println!("Transaction signed successfully");
Parameters and Returns
See the Rust SDK documentation for detailed parameter and return types, including embedded examples:For REST API details, see the API reference.To sign a transaction make a A successful response will look like the following:
POST request toReport incorrect code
Copy
Ask AI
https://api.privy.io/v1/wallets/<wallet_id>/rpc
Usage
Report incorrect code
Copy
Ask AI
$ 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 '{
"method": "eth_signTransaction",
"params": {
"transaction": {
"to": "0xE3070d3e4309afA3bC9a6b057685743CF42da77C",
"value": "0x2386F26FC10000",
"chain_id": 1,
"type": 2,
"gas_limit": "0x5208",
"nonce": 1,
"max_fee_per_gas": "0x14bf7dadac",
"max_priority_fee_per_gas": "0xf4240"
}
}
}'
Report incorrect code
Copy
Ask AI
{
"method": "eth_signTransaction",
"data": {
"signed_transaction": "0x28eac519bf4051a624d4246a5788667baf84dcd7d2a439b314b339013b5cdb4c",
"encoding": "rlp"
}
}
Parameters
The RPC method executed with the wallet.
The details of the transaction to send on the chain.
Returns
The RPC method executed with the wallet.
The signed transaction.
The encoding format for the signed transaction. Currently, only
'rlp' is supported for Ethereum.
