EthereumService

Struct EthereumService 

Source
pub struct EthereumService { /* private fields */ }
Expand description

Service for Ethereum-specific wallet operations.

Provides convenient methods for common Ethereum wallet operations such as:

  • Personal message signing (UTF-8 strings and raw bytes)
  • secp256k1 signature generation
  • EIP-712 typed data signing
  • Transaction signing and broadcasting
  • EIP-7702 authorization signing

§Examples

Basic usage:

use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

// Sign a UTF-8 message
let result = ethereum_service
    .sign_message(
        "wallet_id",
        "Hello, Ethereum!",
        &auth_ctx,
        None, // no idempotency key
    )
    .await?;

Implementations§

Source§

impl EthereumService

Source

pub async fn sign_message( &self, wallet_id: &str, message: &str, authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs a UTF-8 encoded message for an Ethereum wallet using the personal_sign method.

This method signs arbitrary UTF-8 text messages using Ethereum’s personal message signing standard. The message will be prefixed with the Ethereum signed message prefix before signing.

§Parameters
  • wallet_id - The ID of the wallet to use for signing
  • message - The UTF-8 message string to be signed
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request to prevent duplicate operations
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the signature data.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

let signature = ethereum_service
    .sign_message(
        "clz2rqy4500061234abcd1234",
        "Hello, Ethereum!",
        &auth_ctx,
        Some("unique-request-id-123"),
    )
    .await?;

println!("Message signed successfully");
§Errors

This method will return an error if:

  • The wallet ID is invalid or not found
  • The authorization context is invalid
  • Network communication fails
  • The signing operation fails on the server
Source

pub async fn sign_message_bytes( &self, wallet_id: &str, message: &[u8], authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs a raw byte array message for an Ethereum wallet using the personal_sign method.

This method signs raw binary data by first encoding it as a hex string (with 0x prefix) and then using Ethereum’s personal message signing standard.

§Parameters
  • wallet_id - The ID of the wallet to use for signing
  • message - The message byte array to be signed
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the signature data.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

let message_bytes = b"Hello, bytes!";
let signature = ethereum_service
    .sign_message_bytes("clz2rqy4500061234abcd1234", message_bytes, &auth_ctx, None)
    .await?;

println!("Byte message signed successfully");
Source

pub async fn sign_secp256k1( &self, wallet_id: &str, hash: &str, authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs a message using secp256k1 signature algorithm.

This method performs low-level secp256k1 signing on a pre-computed hash. The hash should be exactly 32 bytes and is typically the result of keccak256 hashing of the data to be signed.

§Parameters
  • wallet_id - The ID of the wallet to use for signing
  • hash - The hash to sign (typically 32 bytes as hex string with 0x prefix)
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the secp256k1 signature.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

// Pre-computed keccak256 hash
let hash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
let signature = ethereum_service
    .sign_secp256k1("clz2rqy4500061234abcd1234", hash, &auth_ctx, None)
    .await?;

println!("Hash signed with secp256k1");
§Notes

This is a lower-level signing method. For most use cases, prefer sign_message() or sign_typed_data() which handle the hashing automatically.

Source

pub async fn sign_7702_authorization( &self, wallet_id: &str, params: EthereumSign7702AuthorizationRpcInputParams, authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs a 7702 authorization using the eth_sign7702Authorization RPC method.

EIP-7702 introduces account abstraction by allowing EOAs to temporarily delegate control to a smart contract. This method signs the authorization that allows the delegation to take place.

§Parameters
  • wallet_id - The ID of the wallet to use for signing
  • params - The parameters for the eth_sign7702Authorization RPC method including contract address, chain ID, and nonce
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the signed authorization data.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

let params = EthereumSign7702AuthorizationRpcInputParams {
    chain_id: EthereumSign7702AuthorizationRpcInputParamsChainId::Integer(1),
    contract: "0x1234567890abcdef1234567890abcdef12345678".to_string(),
    nonce: None,
};

let authorization = ethereum_service
    .sign_7702_authorization("clz2rqy4500061234abcd1234", params, &auth_ctx, None)
    .await?;

println!("7702 authorization signed successfully");
Source

pub async fn sign_typed_data( &self, wallet_id: &str, typed_data: EthereumSignTypedDataRpcInputParamsTypedData, authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs typed data using EIP-712 standard.

EIP-712 defines a standard for typed structured data signing that provides better UX and security compared to signing arbitrary strings. This method implements the eth_signTypedData_v4 RPC method.

§Parameters
  • wallet_id - The ID of the wallet to use for signing
  • typed_data - The typed data structure to be signed, conforming to EIP-712 format
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the signed typed data.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

// Create EIP-712 typed data structure
let typed_data = EthereumSignTypedDataRpcInputParamsTypedData {
    domain: Default::default(),
    message: Default::default(),
    primary_type: "Mail".to_string(),
    types: Default::default(),
};

let signature = ethereum_service
    .sign_typed_data("clz2rqy4500061234abcd1234", typed_data, &auth_ctx, None)
    .await?;

println!("Typed data signed successfully");
§Notes

The typed data must conform to the EIP-712 specification with proper domain, types, primaryType, and message fields. Refer to EIP-712 for the complete specification of the required structure.

Source

pub async fn sign_transaction( &self, wallet_id: &str, transaction: EthereumSignTransactionRpcInputParamsTransaction, authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs a transaction using the eth_signTransaction method.

This method signs an Ethereum transaction but does not broadcast it to the network. The signed transaction can be broadcast later using other tools or the send_transaction method.

§Parameters
  • wallet_id - The ID of the wallet to use for signing
  • transaction - The transaction object to be signed including to, value, data, gas, etc.
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the signed transaction data.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

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("clz2rqy4500061234abcd1234", transaction, &auth_ctx, None)
    .await?;

println!("Transaction signed successfully");
Source

pub async fn send_transaction( &self, wallet_id: &str, caip2: &str, transaction: EthereumSendTransactionRpcInputParamsTransaction, authorization_context: &AuthorizationContext, idempotency_key: Option<&str>, ) -> Result<ResponseValue<WalletRpcResponse>, PrivySignedApiError>

Signs and sends a transaction using the eth_sendTransaction method.

This method both signs and broadcasts an Ethereum transaction to the specified network. It’s a convenience method that combines signing and sending in one operation.

§Parameters
  • wallet_id - The ID of the wallet used for the transaction
  • caip2 - The CAIP-2 chain ID of the Ethereum network (e.g., “eip155:1” for Ethereum Mainnet, “eip155:11155111” for Sepolia)
  • transaction - The transaction object to be sent
  • authorization_context - The authorization context containing JWT or private keys for request signing
  • idempotency_key - Optional idempotency key for the request
§Returns

Returns a ResponseValue<WalletRpcResponse> containing the transaction hash or other relevant data.

§Examples
use privy_rs::{AuthorizationContext, generated::types::*};

let ethereum_service = client.wallets().ethereum();
let auth_ctx = AuthorizationContext::new();

let transaction = EthereumSendTransactionRpcInputParamsTransaction {
    to: Some("0x742d35Cc6635C0532925a3b8c17d6d1E9C2F7ca".to_string()),
    value: None,
    gas_limit: None,
    max_fee_per_gas: None,
    max_priority_fee_per_gas: None,
    data: Some("0x".to_string()),
    chain_id: None,
    from: None,
    gas_price: None,
    nonce: None,
    type_: None,
};

let result = ethereum_service
    .send_transaction(
        "clz2rqy4500061234abcd1234",
        "eip155:1",
        transaction,
        &auth_ctx,
        None,
    )
    .await?;

println!("Transaction sent successfully");
§Notes
  • The transaction will be broadcast to the network specified by the CAIP-2 chain ID
  • This method requires sufficient balance in the wallet to cover gas costs and transfer value
  • The transaction will be mined and included in a block if successful
  • Common CAIP-2 chain IDs: “eip155:1” (Ethereum), “eip155:137” (Polygon), “eip155:11155111” (Sepolia testnet)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more