pub struct TransactionRequest {Show 16 fields
pub from: Option<Address>,
pub to: Option<TxKind>,
pub gas_price: Option<u128>,
pub max_fee_per_gas: Option<u128>,
pub max_priority_fee_per_gas: Option<u128>,
pub max_fee_per_blob_gas: Option<u128>,
pub gas: Option<u64>,
pub value: Option<U256>,
pub input: TransactionInput,
pub nonce: Option<u64>,
pub chain_id: Option<ChainId>,
pub access_list: Option<AccessList>,
pub transaction_type: Option<u8>,
pub blob_versioned_hashes: Option<Vec<B256>>,
pub sidecar: Option<BlobTransactionSidecar>,
pub authorization_list: Option<Vec<SignedAuthorization>>,
}
Expand description
Represents all transaction requests to/from RPC.
Fields§
§from: Option<Address>
The address of the transaction author.
to: Option<TxKind>
The destination address of the transaction.
gas_price: Option<u128>
The legacy gas price.
max_fee_per_gas: Option<u128>
The max base fee per gas the sender is willing to pay.
max_priority_fee_per_gas: Option<u128>
The max priority fee per gas the sender is willing to pay, also called the miner tip.
max_fee_per_blob_gas: Option<u128>
The max fee per blob gas for EIP-4844 blob transactions.
gas: Option<u64>
The gas limit for the transaction.
value: Option<U256>
The value transferred in the transaction, in wei.
input: TransactionInput
Transaction data.
nonce: Option<u64>
The nonce of the transaction.
chain_id: Option<ChainId>
The chain ID for the transaction.
access_list: Option<AccessList>
An EIP-2930 access list, which lowers cost for accessing accounts and storages in the list. See EIP-2930 for more information.
transaction_type: Option<u8>
The EIP-2718 transaction type. See EIP-2718 for more information.
blob_versioned_hashes: Option<Vec<B256>>
Blob versioned hashes for EIP-4844 transactions.
sidecar: Option<BlobTransactionSidecar>
Blob sidecar for EIP-4844 transactions.
Authorization list for EIP-7702 transactions.
Implementations§
Source§impl TransactionRequest
impl TransactionRequest
Sourcepub const fn from(self, from: Address) -> Self
pub const fn from(self, from: Address) -> Self
Sets the from
field in the call to the provided address
Sourcepub fn from_transaction<T: TransactionTrait>(tx: T) -> Self
pub fn from_transaction<T: TransactionTrait>(tx: T) -> Self
Initializes the TransactionRequest
with the provided transaction.
Note: This leaves the from
field empty.
Sourcepub fn from_recovered_transaction<T: TransactionTrait>(tx: Recovered<T>) -> Self
pub fn from_recovered_transaction<T: TransactionTrait>(tx: Recovered<T>) -> Self
Initializes the TransactionRequest
with the provided transaction and sender.
Sourcepub fn from_transaction_with_sender<T: TransactionTrait>(
tx: T,
from: Address,
) -> Self
pub fn from_transaction_with_sender<T: TransactionTrait>( tx: T, from: Address, ) -> Self
Initializes the TransactionRequest
with the provided transaction and sender.
Sourcepub const fn transaction_type(self, transaction_type: u8) -> Self
pub const fn transaction_type(self, transaction_type: u8) -> Self
Sets the transactions type for the transactions.
Sourcepub const fn max_fee_per_gas(self, max_fee_per_gas: u128) -> Self
pub const fn max_fee_per_gas(self, max_fee_per_gas: u128) -> Self
Sets the maximum fee per gas for the transaction.
Sourcepub const fn max_priority_fee_per_gas(
self,
max_priority_fee_per_gas: u128,
) -> Self
pub const fn max_priority_fee_per_gas( self, max_priority_fee_per_gas: u128, ) -> Self
Sets the maximum priority fee per gas for the transaction.
Sourcepub const fn max_fee_per_blob_gas(self, max_fee_per_blob_gas: u128) -> Self
pub const fn max_fee_per_blob_gas(self, max_fee_per_blob_gas: u128) -> Self
Sets the maximum fee per blob gas for the transaction.
Sourcepub fn access_list(self, access_list: AccessList) -> Self
pub fn access_list(self, access_list: AccessList) -> Self
Sets the access list for the transaction.
Sourcepub fn input(self, input: TransactionInput) -> Self
pub fn input(self, input: TransactionInput) -> Self
Sets the input data for the transaction.
This can be used to set both input
and the data
field, because some chains or services
still expect of the deprecated data
field
use alloy_rpc_types_eth::{TransactionInput, TransactionRequest};
let req = TransactionRequest::default().input(TransactionInput::both(b"00".into()));
Sourcepub fn normalize_input(&mut self)
pub fn normalize_input(&mut self)
Ensures that if either input
or data
is set, the input
field contains the value.
This removes data
the data field.
Sourcepub fn normalized_input(self) -> Self
pub fn normalized_input(self) -> Self
Consumes the type and returns it with Self::normalize_input
applied
Sourcepub fn normalize_data(&mut self)
pub fn normalize_data(&mut self)
Ensures that if either data
or input
is set, the data
field contains the value.
This removes input
the data field.
Sourcepub fn normalized_data(self) -> Self
pub fn normalized_data(self) -> Self
Consumes the type and returns it with Self::normalize_data
applied
Sourcepub fn set_input_and_data(&mut self)
pub fn set_input_and_data(&mut self)
If only one field is set, this also sets the other field by with that value.
This is a noop if both fields are already set.
Sourcepub fn with_input_and_data(self) -> Self
pub fn with_input_and_data(self) -> Self
Consumes the type and returns it with Self::set_input_and_data
applied.
Sourcepub fn fee_cap(&self) -> Option<u128>
pub fn fee_cap(&self) -> Option<u128>
Returns the configured fee cap, if any.
The returns gas_price
(legacy) if set or max_fee_per_gas
(EIP1559)
Sourcepub const fn has_eip4844_fields(&self) -> bool
pub const fn has_eip4844_fields(&self) -> bool
Returns true if any of the EIP-4844 fields are set:
- blob sidecar
- blob versioned hashes
- max fee per blob gas
Sourcepub const fn has_eip1559_fields(&self) -> bool
pub const fn has_eip1559_fields(&self) -> bool
Returns true if any of the EIP-1559 fee fields are set:
- max fee per gas
- max priority fee per gas
Sourcepub fn populate_blob_hashes(&mut self)
pub fn populate_blob_hashes(&mut self)
Populate the blob_versioned_hashes
key, if a sidecar exists. No
effect otherwise.
Sourcepub fn get_invalid_common_fields(&self) -> Vec<&'static str>
pub fn get_invalid_common_fields(&self) -> Vec<&'static str>
Gets invalid fields for all transaction types
Sourcepub fn get_invalid_1559_fields(&self) -> Vec<&'static str>
pub fn get_invalid_1559_fields(&self) -> Vec<&'static str>
Gets invalid fields for EIP-1559 transaction type
Sourcepub fn build_legacy(self) -> Result<TxLegacy, ValueError<Self>>
pub fn build_legacy(self) -> Result<TxLegacy, ValueError<Self>>
Build a legacy transaction.
Returns an error if required fields are missing.
Use complete_legacy
to check if the request can be built.
Sourcepub fn build_1559(self) -> Result<TxEip1559, ValueError<Self>>
pub fn build_1559(self) -> Result<TxEip1559, ValueError<Self>>
Build an EIP-1559 transaction.
Returns ane error if required fields are missing. Use complete_1559
to check if the
request can be built.
Sourcepub fn build_2930(self) -> Result<TxEip2930, ValueError<Self>>
pub fn build_2930(self) -> Result<TxEip2930, ValueError<Self>>
Build an EIP-2930 transaction.
Returns an error if required fields are missing. Use complete_2930
to check if the
request can be built.
Sourcepub fn build_4844_variant(self) -> Result<TxEip4844Variant, ValueError<Self>>
pub fn build_4844_variant(self) -> Result<TxEip4844Variant, ValueError<Self>>
Build an EIP-4844 transaction variant - either with or without sidecar.
Returns an error if required fields are missing. Use complete_4844
to check if the
request can be built.
Sourcepub fn build_4844_without_sidecar(self) -> Result<TxEip4844, ValueError<Self>>
pub fn build_4844_without_sidecar(self) -> Result<TxEip4844, ValueError<Self>>
Build an EIP-4844 transaction without sidecar.
Returns an error if required fields are missing. Use complete_4844
to check if the
request can be built.
Sourcepub fn build_4844_with_sidecar(
self,
) -> Result<TxEip4844WithSidecar, ValueError<Self>>
pub fn build_4844_with_sidecar( self, ) -> Result<TxEip4844WithSidecar, ValueError<Self>>
Build an EIP-4844 transaction with sidecar.
Returns an error if required fields are missing. Use complete_4844
to check if the
request can be built.
Sourcepub fn build_7702(self) -> Result<TxEip7702, ValueError<Self>>
pub fn build_7702(self) -> Result<TxEip7702, ValueError<Self>>
Build an EIP-7702 transaction.
§Panics
If required fields are missing. Use complete_7702
to check if the
request can be built.
Sourcepub fn trim_conflicting_keys(&mut self)
pub fn trim_conflicting_keys(&mut self)
Trim field conflicts, based on the preferred type
This is used to ensure that the request will not be rejected by the server due to conflicting keys, and should only be called before submission via rpc.
Sourcepub const fn minimal_tx_type(&self) -> TxType
pub const fn minimal_tx_type(&self) -> TxType
Returns the minimal transaction type this request can be converted into based on the fields that are set.
Compared to Self::preferred_type
which is intended for building and eventually signing
transactions and which prefers TxType::Eip1559
if no conflicting fields are set, this
function is intended for deriving the minimal transaction type (legacy).
Self::minimal_tx_type
is mostly relevant for the server-side, for example executing
eth_calls
against historic state (pre TxType::Eip1559
) and is used to configure the
EVM’s transaction environment with the minimal settings.
Whereas Self::preferred_type
is recommend for using client-side (filling a
TransactionRequest
and signing the transaction TransactionRequest::build_typed_tx
).
The type is determined in the following order:
- EIP-7702 if authorization_list is set
- EIP-4844 if any EIP-4844 fields are set (sidecar, blob hashes, max blob fee)
- EIP-1559 if any EIP-1559 fee fields are set (max fee per gas, max priority fee)
- EIP-2930 if access_list is set
- Legacy otherwise
§Examples
use alloy_consensus::TxType;
use alloy_eips::eip2930::AccessList;
use alloy_rpc_types_eth::TransactionRequest;
// EIP-7702 (highest priority)
let mut request = TransactionRequest::default();
request.authorization_list = Some(vec![]);
assert_eq!(request.minimal_tx_type(), TxType::Eip7702);
// EIP-4844 with max_fee_per_blob_gas
let request = TransactionRequest::default().max_fee_per_blob_gas(1000000000);
assert_eq!(request.minimal_tx_type(), TxType::Eip4844);
// EIP-1559 with max_fee_per_gas
let request = TransactionRequest::default().max_fee_per_gas(2000000000);
assert_eq!(request.minimal_tx_type(), TxType::Eip1559);
// EIP-1559 with max_priority_fee_per_gas
let request = TransactionRequest::default().max_priority_fee_per_gas(1000000000);
assert_eq!(request.minimal_tx_type(), TxType::Eip1559);
// EIP-2930 with access_list
let request = TransactionRequest::default().access_list(AccessList::default());
assert_eq!(request.minimal_tx_type(), TxType::Eip2930);
// Legacy (default fallback)
let request = TransactionRequest::default();
assert_eq!(request.minimal_tx_type(), TxType::Legacy);
// Priority example: EIP-4844 overrides EIP-1559
let mut request = TransactionRequest::default()
.max_fee_per_gas(2000000000) // EIP-1559 (ignored)
.max_fee_per_blob_gas(1000000000); // EIP-4844 (takes priority)
assert_eq!(request.minimal_tx_type(), TxType::Eip4844);
Sourcepub const fn preferred_type(&self) -> TxType
pub const fn preferred_type(&self) -> TxType
Check this builder’s preferred type, based on the fields that are set.
This function is intended for building and eventually signing transactions client-side.
Unlike Self::minimal_tx_type
which returns the minimal required type, this function
prefers TxType::Eip1559
when no conflicting fields are set.
Types are preferred as follows:
- EIP-7702 if authorization_list is set
- EIP-4844 if sidecar or max_blob_fee_per_gas is set
- EIP-2930 if access_list is set
- Legacy if gas_price is set and access_list is unset
- EIP-1559 in all other cases
§Examples
use alloy_consensus::TxType;
use alloy_eips::eip2930::AccessList;
use alloy_rpc_types_eth::TransactionRequest;
// EIP-7702 (highest priority)
let mut request = TransactionRequest::default();
request.authorization_list = Some(vec![]);
assert_eq!(request.preferred_type(), TxType::Eip7702);
// EIP-4844 with max_fee_per_blob_gas
let request = TransactionRequest::default().max_fee_per_blob_gas(1000000000);
assert_eq!(request.preferred_type(), TxType::Eip4844);
// EIP-2930 with both access_list and gas_price
let request =
TransactionRequest::default().access_list(AccessList::default()).gas_price(20000000000);
assert_eq!(request.preferred_type(), TxType::Eip2930);
// Legacy with only gas_price (no access_list)
let request = TransactionRequest::default().gas_price(20000000000);
assert_eq!(request.preferred_type(), TxType::Legacy);
// EIP-1559 as default for modern transactions
let request = TransactionRequest::default();
assert_eq!(request.preferred_type(), TxType::Eip1559);
// EIP-1559 even with access_list but no gas_price
let request = TransactionRequest::default().access_list(AccessList::default());
assert_eq!(request.preferred_type(), TxType::Eip1559);
§Key Differences from Self::minimal_tx_type
use alloy_consensus::TxType;
use alloy_eips::eip2930::AccessList;
use alloy_rpc_types_eth::TransactionRequest;
// Empty request - preferred_type prefers EIP-1559, minimal_tx_type falls back to Legacy
let request = TransactionRequest::default();
assert_eq!(request.preferred_type(), TxType::Eip1559); // Preferred for new txs
assert_eq!(request.minimal_tx_type(), TxType::Legacy); // Minimal requirement
// Access list only - different behavior
let request = TransactionRequest::default().access_list(AccessList::default());
assert_eq!(request.preferred_type(), TxType::Eip1559); // Still prefers EIP-1559
assert_eq!(request.minimal_tx_type(), TxType::Eip2930); // Minimal is EIP-2930
// Gas price only - both agree on Legacy
let request = TransactionRequest::default().gas_price(20000000000);
assert_eq!(request.preferred_type(), TxType::Legacy);
assert_eq!(request.minimal_tx_type(), TxType::Legacy);
Sourcepub fn missing_keys(&self) -> Result<TxType, (TxType, Vec<&'static str>)>
pub fn missing_keys(&self) -> Result<TxType, (TxType, Vec<&'static str>)>
Check if all necessary keys are present to build a transaction.
§Returns
- Ok(type) if all necessary keys are present to build the preferred type.
- Err((type, missing)) if some keys are missing to build the preferred type.
Sourcepub fn complete_4844(&self) -> Result<(), Vec<&'static str>>
pub fn complete_4844(&self) -> Result<(), Vec<&'static str>>
Check if all necessary keys are present to build a 4844 transaction, returning a list of keys that are missing.
NOTE: sidecar
must be present, even if blob_versioned_hashes
is set.
Sourcepub fn complete_1559(&self) -> Result<(), Vec<&'static str>>
pub fn complete_1559(&self) -> Result<(), Vec<&'static str>>
Check if all necessary keys are present to build a 1559 transaction, returning a list of keys that are missing.
Sourcepub fn complete_2930(&self) -> Result<(), Vec<&'static str>>
pub fn complete_2930(&self) -> Result<(), Vec<&'static str>>
Check if all necessary keys are present to build a 2930 transaction, returning a list of keys that are missing.
Sourcepub fn complete_7702(&self) -> Result<(), Vec<&'static str>>
pub fn complete_7702(&self) -> Result<(), Vec<&'static str>>
Check if all necessary keys are present to build a 7702 transaction, returning a list of keys that are missing.
Sourcepub fn complete_legacy(&self) -> Result<(), Vec<&'static str>>
pub fn complete_legacy(&self) -> Result<(), Vec<&'static str>>
Check if all necessary keys are present to build a legacy transaction, returning a list of keys that are missing.
Sourcepub fn buildable_type(&self) -> Option<TxType>
pub fn buildable_type(&self) -> Option<TxType>
Return the tx type this request can be built as. Computed by checking the preferred type, and then checking for completeness.
Sourcepub fn build_typed_tx(self) -> Result<TypedTransaction, Self>
pub fn build_typed_tx(self) -> Result<TypedTransaction, Self>
Build a TypedTransaction
When Ok(...)
is returned, the TypedTransaction
is guaranteed to be complete. Which
is to say, that it is signable, and the signed version can be sent to the network.
Sourcepub fn build_consensus_tx(self) -> Result<TypedTransaction, BuildTransactionErr>
pub fn build_consensus_tx(self) -> Result<TypedTransaction, BuildTransactionErr>
Build a TypedTransaction
.
When Ok(...)
is returned, the TypedTransaction
is not guaranteed to be complete,
only signable.
E.g. a particular case is when the transaction is of type Eip4844
and the sidecar
is not
set, in this case the transaction is not complete, i.e. it cannot be sent to the network
once signed. However, it can still be used to calculate the signing hash, signature of
the transaction, and transaction trie hash.
In case the requirement is to build a complete transaction, use build_typed_tx
instead.
Sourcepub fn build_typed_simulate_transaction(
self,
) -> Result<EthereumTxEnvelope<TxEip4844>, ValueError<Self>>
pub fn build_typed_simulate_transaction( self, ) -> Result<EthereumTxEnvelope<TxEip4844>, ValueError<Self>>
Builds a signed typed transaction envelope for the eth_simulateV1
endpoint with a dummy
signature. See also https://github.com/ethereum/execution-apis/pull/484
Returns an error if the transaction is not buildable, i.e. if the required fields are
missing. See Self::buildable_type
for more information.
Trait Implementations§
Source§impl AsMut<TransactionRequest> for TransactionRequest
impl AsMut<TransactionRequest> for TransactionRequest
Source§impl AsRef<TransactionRequest> for TransactionRequest
impl AsRef<TransactionRequest> for TransactionRequest
Source§impl Clone for TransactionRequest
impl Clone for TransactionRequest
Source§fn clone(&self) -> TransactionRequest
fn clone(&self) -> TransactionRequest
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TransactionRequest
impl Debug for TransactionRequest
Source§impl Default for TransactionRequest
impl Default for TransactionRequest
Source§fn default() -> TransactionRequest
fn default() -> TransactionRequest
Source§impl<'de> Deserialize<'de> for TransactionRequest
impl<'de> Deserialize<'de> for TransactionRequest
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<EthereumTxEnvelope<TxEip4844Variant>> for TransactionRequest
impl From<EthereumTxEnvelope<TxEip4844Variant>> for TransactionRequest
Source§fn from(envelope: TxEnvelope) -> Self
fn from(envelope: TxEnvelope) -> Self
Source§impl From<EthereumTypedTransaction<TxEip4844Variant>> for TransactionRequest
impl From<EthereumTypedTransaction<TxEip4844Variant>> for TransactionRequest
Source§fn from(tx: TypedTransaction) -> Self
fn from(tx: TypedTransaction) -> Self
Source§impl From<Transaction> for TransactionRequest
impl From<Transaction> for TransactionRequest
Source§fn from(tx: Transaction) -> Self
fn from(tx: Transaction) -> Self
Source§impl From<TransactionRequest> for WithOtherFields<TransactionRequest>
impl From<TransactionRequest> for WithOtherFields<TransactionRequest>
Source§fn from(tx: TransactionRequest) -> Self
fn from(tx: TransactionRequest) -> Self
Source§impl From<TxEip1559> for TransactionRequest
impl From<TxEip1559> for TransactionRequest
Source§impl From<TxEip2930> for TransactionRequest
impl From<TxEip2930> for TransactionRequest
Source§impl From<TxEip4844> for TransactionRequest
impl From<TxEip4844> for TransactionRequest
Source§impl From<TxEip4844Variant> for TransactionRequest
impl From<TxEip4844Variant> for TransactionRequest
Source§fn from(tx: TxEip4844Variant) -> Self
fn from(tx: TxEip4844Variant) -> Self
Source§impl From<TxEip4844WithSidecar> for TransactionRequest
impl From<TxEip4844WithSidecar> for TransactionRequest
Source§fn from(tx: TxEip4844WithSidecar) -> Self
fn from(tx: TxEip4844WithSidecar) -> Self
Source§impl From<TxEip7702> for TransactionRequest
impl From<TxEip7702> for TransactionRequest
Source§impl From<TxLegacy> for TransactionRequest
impl From<TxLegacy> for TransactionRequest
Source§impl Hash for TransactionRequest
impl Hash for TransactionRequest
Source§impl PartialEq for TransactionRequest
impl PartialEq for TransactionRequest
Source§impl Serialize for TransactionRequest
impl Serialize for TransactionRequest
Source§impl TransactionBuilder4844 for TransactionRequest
impl TransactionBuilder4844 for TransactionRequest
Source§fn max_fee_per_blob_gas(&self) -> Option<u128>
fn max_fee_per_blob_gas(&self) -> Option<u128>
Source§fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128)
fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128)
Source§fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar>
fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar>
Source§fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar)
fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar)
Source§fn with_max_fee_per_blob_gas(self, max_fee_per_blob_gas: u128) -> Self
fn with_max_fee_per_blob_gas(self, max_fee_per_blob_gas: u128) -> Self
Source§fn with_blob_sidecar(self, sidecar: BlobTransactionSidecar) -> Self
fn with_blob_sidecar(self, sidecar: BlobTransactionSidecar) -> Self
Source§impl TransactionBuilder7702 for TransactionRequest
impl TransactionBuilder7702 for TransactionRequest
impl Eq for TransactionRequest
impl StructuralPartialEq for TransactionRequest
Auto Trait Implementations§
impl !Freeze for TransactionRequest
impl RefUnwindSafe for TransactionRequest
impl Send for TransactionRequest
impl Sync for TransactionRequest
impl Unpin for TransactionRequest
impl UnwindSafe for TransactionRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more