pub enum Transaction {
    Legacy {
        nonce: Uint256,
        gas_price: Uint256,
        gas_limit: Uint256,
        to: Address,
        value: Uint256,
        data: Vec<u8>,
        signature: Option<Signature>,
    },
    Eip2930 {
        access_list: Vec<(Address, Vec<Uint256>)>,
        chain_id: Uint256,
        signature: Option<Signature>,
        nonce: Uint256,
        gas_price: Uint256,
        gas_limit: Uint256,
        to: Address,
        value: Uint256,
        data: Vec<u8>,
    },
    Eip1559 {
        chain_id: Uint256,
        nonce: Uint256,
        max_priority_fee_per_gas: Uint256,
        max_fee_per_gas: Uint256,
        gas_limit: Uint256,
        to: Address,
        value: Uint256,
        data: Vec<u8>,
        signature: Option<Signature>,
        access_list: Vec<(Address, Vec<Uint256>)>,
    },
}

Variants§

§

Legacy

The original Ethereum transaction format, will always start with a byte >=0xc0

Fields

§nonce: Uint256

Replay prevention counter, this must be the last nonce successfully on the chain plus one, multiple tx with incrementing nonces can wait in the mempool but they must execute in order. If you have multiple tx in the pool, one with a lower nonce fails, and is then replaced the following tx will execute immediately

§gas_price: Uint256

The price of gas for this transaction, total spend will be price * limit with no refund for actual utilization

§gas_limit: Uint256

The maximum amount of gas that can be used by this transaction, total spend will be price * limit with no refund for if the actual utilization is below this value

§to: Address

The destination address, this can be a contract or another account, in the contract case the data field will be populated with an encoded contract call

§value: Uint256

The amount of Ether to send with this transaction, while this can be used with contract calls see ERC-1363, it’s mostly used for Ether transfers. Remember ERC20 ERC721 and other non Ether ‘tokens’ are contact calls! So an ERC20 send will have zero here

§data: Vec<u8>

Encoded contract call or contract creation

§signature: Option<Signature>
§

Eip2930

using an access list

Fields

§access_list: Vec<(Address, Vec<Uint256>)>

A list of addresses mapped to storage keys access within this range is cheaper in terms of gas for this tx type as an incentive to assist with node optimization

§chain_id: Uint256

Chain-id value, used to prevent replay attacks accross chains

§signature: Option<Signature>

The signature, encoded such that the V value is a boolean and does not include an encoded chain id

§nonce: Uint256

Replay prevention counter, this must be the last nonce successfully on the chain plus one, multiple tx with incrementing nonces can wait in the mempool but they must execute in order. If you have multiple tx in the pool, one with a lower nonce fails, and is then replaced the following tx will execute immediately

§gas_price: Uint256

The price of gas for this transaction, total spend will be price * limit with no refund for actual utilization

§gas_limit: Uint256

The maximum amount of gas that can be used by this transaction, total spend will be price * limit with no refund for if the actual utilization is below this value

§to: Address

The destination address, this can be a contract or another account, in the contract case the data field will be populated with an encoded contract call

§value: Uint256

The amount of Ether to send with this transaction, while this can be used with contract calls see ERC-1363, it’s mostly used for Ether transfers. Remember ERC20 ERC721 and other non Ether ‘tokens’ are contact calls! So an ERC20 send will have zero here

§data: Vec<u8>

Encoded contract call or contract creation

§

Eip1559

Fields

§chain_id: Uint256

Chain-id value, used to prevent replay attacks accross chains

§nonce: Uint256

Replay prevention counter, this must be the last nonce successfully on the chain plus one, multiple tx with incrementing nonces can wait in the mempool but they must execute in order. If you have multiple tx in the pool, one with a lower nonce fails, and is then replaced the following tx will execute immediately

§max_priority_fee_per_gas: Uint256
§max_fee_per_gas: Uint256
§gas_limit: Uint256
§to: Address

The destination address, this can be a contract or another account, in the contract case the data field will be populated with an encoded contract call

§value: Uint256

The amount of Ether to send with this transaction, while this can be used with contract calls see ERC-1363, it’s mostly used for Ether transfers. Remember ERC20 ERC721 and other non Ether ‘tokens’ are contact calls! So an ERC20 send will have zero here

§data: Vec<u8>

Encoded contract call or contract creation

§signature: Option<Signature>
§access_list: Vec<(Address, Vec<Uint256>)>

A list of addresses mapped to storage keys access within this range is cheaper in terms of gas for this tx type as an incentive to assist with node optimization

Implementations§

source§

impl Transaction

source

pub fn is_valid(&self) -> bool

source

pub fn get_signature(&self) -> Option<Signature>

source

pub fn get_nonce(&self) -> Uint256

source

pub fn get_data(&self) -> Vec<u8>

source

pub fn as_data(self) -> Vec<u8>

source

pub fn data_ref(&self) -> &[u8]

source

pub fn get_to(&self) -> Address

source

pub fn get_value(&self) -> Uint256

source

pub fn get_gas_limit(&self) -> Uint256

source

pub fn set_gas_limit(&mut self, limit: Uint256)

source

pub fn set_max_fee_per_gas(&mut self, max_fee: Uint256)

source

pub fn set_max_priority_fee_per_gas(&mut self, max_fee: Uint256)

source

pub fn set_gas_price(&mut self, new_gas_price: Uint256)

source

pub fn intrinsic_gas_used(&self) -> Uint256

source

pub fn sign(&self, key: &PrivateKey, network_id: Option<u64>) -> Transaction

Signs the provided transaction, with a legacy format signature if a network_id is provided WARNING: network_id MUST be provided for Legacy transactions, or else replay attacks are possible

source

pub fn sender(&self) -> Result<Address, Error>

Get the sender’s Address; derived from the signature field, does not keep with convention returns error if the signature is invalid. Traditional return would be constants::NULL_ADDRESS you may need to insert that yourself after matching on errors

source

pub fn hash(&self) -> Vec<u8>

Creates a hash of a transaction given all TX attributes including signature (VRS) whether it is present, or not.

source

pub fn txid(&self) -> Uint256

Generates the TXID of this transaction

source

pub fn to_bytes(&self) -> Vec<u8>

Creates a byte representation of this transaction

source

pub fn to_rlp_bytes(&self) -> Vec<u8>

Generates rlp ethereum encoded byte format of this transaction

source

pub fn decode_from_rlp(raw_rlp_bytes: &[u8]) -> Result<Self, Error>

Creates a transaction from raw RLP bytes, can not decode unsigned transactions

Trait Implementations§

source§

impl Clone for Transaction

source§

fn clone(&self) -> Transaction

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Transaction

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LowerHex for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl PartialEq for Transaction

source§

fn eq(&self, other: &Transaction) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Transaction

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl UpperHex for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Eq for Transaction

source§

impl StructuralPartialEq for Transaction

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<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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, 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.