gleeth/crypto/transaction

Types

Access list entry for EIP-2930

pub type AccessListEntry {
  AccessListEntry(address: String, storage_keys: List(String))
}

Constructors

  • AccessListEntry(address: String, storage_keys: List(String))

EIP-1559 transaction parameters (Type 2 transactions)

pub type Eip1559Transaction {
  Eip1559Transaction(
    to: String,
    value: String,
    gas_limit: String,
    max_fee_per_gas: String,
    max_priority_fee_per_gas: String,
    nonce: String,
    data: String,
    chain_id: Int,
    access_list: List(AccessListEntry),
  )
}

Constructors

  • Eip1559Transaction(
      to: String,
      value: String,
      gas_limit: String,
      max_fee_per_gas: String,
      max_priority_fee_per_gas: String,
      nonce: String,
      data: String,
      chain_id: Int,
      access_list: List(AccessListEntry),
    )

Represents a signed EIP-1559 (Type 2) transaction

pub type SignedEip1559Transaction {
  SignedEip1559Transaction(
    to: String,
    value: String,
    gas_limit: String,
    max_fee_per_gas: String,
    max_priority_fee_per_gas: String,
    nonce: String,
    data: String,
    chain_id: Int,
    access_list: List(AccessListEntry),
    v: String,
    r: String,
    s: String,
    raw_transaction: String,
  )
}

Constructors

  • SignedEip1559Transaction(
      to: String,
      value: String,
      gas_limit: String,
      max_fee_per_gas: String,
      max_priority_fee_per_gas: String,
      nonce: String,
      data: String,
      chain_id: Int,
      access_list: List(AccessListEntry),
      v: String,
      r: String,
      s: String,
      raw_transaction: String,
    )

Represents a signed Ethereum transaction

pub type SignedTransaction {
  SignedTransaction(
    to: String,
    value: String,
    gas_limit: String,
    gas_price: String,
    nonce: String,
    data: String,
    chain_id: Int,
    v: String,
    r: String,
    s: String,
    raw_transaction: String,
  )
}

Constructors

  • SignedTransaction(
      to: String,
      value: String,
      gas_limit: String,
      gas_price: String,
      nonce: String,
      data: String,
      chain_id: Int,
      v: String,
      r: String,
      s: String,
      raw_transaction: String,
    )

Error types for transaction operations

pub type TransactionError {
  InvalidAddress(String)
  InvalidAmount(String)
  InvalidGas(String)
  InvalidNonce(String)
  InvalidChainId(String)
  InvalidData(String)
  SigningFailed(String)
  EncodingFailed(String)
}

Constructors

  • InvalidAddress(String)
  • InvalidAmount(String)
  • InvalidGas(String)
  • InvalidNonce(String)
  • InvalidChainId(String)
  • InvalidData(String)
  • SigningFailed(String)
  • EncodingFailed(String)

Transaction type enumeration

pub type TransactionType {
  Legacy
  AccessList
  Eip1559
}

Constructors

  • Legacy
  • AccessList
  • Eip1559

Represents an Ethereum transaction before signing

pub type UnsignedTransaction {
  UnsignedTransaction(
    to: String,
    value: String,
    gas_limit: String,
    gas_price: String,
    nonce: String,
    data: String,
    chain_id: Int,
  )
}

Constructors

  • UnsignedTransaction(
      to: String,
      value: String,
      gas_limit: String,
      gas_price: String,
      nonce: String,
      data: String,
      chain_id: Int,
    )

Values

pub const arbitrum_chain_id: Int

Arbitrum One chain ID

pub fn create_contract_call(
  contract_address: String,
  call_data: String,
  gas_limit: String,
  gas_price: String,
  nonce: String,
  chain_id: Int,
) -> Result(UnsignedTransaction, TransactionError)

Create a contract interaction transaction (zero value).

Convenience wrapper around create_legacy_transaction with value set to "0x0". All numeric parameters are 0x-prefixed hex strings.

pub fn create_eip1559_transaction(
  to: String,
  value: String,
  gas_limit: String,
  max_fee_per_gas: String,
  max_priority_fee_per_gas: String,
  nonce: String,
  data: String,
  chain_id: Int,
  access_list: List(AccessListEntry),
) -> Result(Eip1559Transaction, TransactionError)

Create and validate an EIP-1559 (Type 2) transaction.

All numeric parameters must be 0x-prefixed hex strings. Fee parameters from methods.get_gas_price and methods.get_max_priority_fee can be passed directly.

  • to - recipient address
  • value - amount in wei as hex
  • gas_limit - gas limit as hex
  • max_fee_per_gas - maximum total fee per gas in wei as hex
  • max_priority_fee_per_gas - tip per gas in wei as hex
  • nonce - sender’s transaction count as hex
  • data - calldata as hex ("0x" for simple transfers)
  • chain_id - network chain ID as integer
  • access_list - EIP-2930 access list (pass [] if not needed)
pub fn create_eth_transfer(
  to: String,
  value_wei: String,
  gas_limit: String,
  gas_price: String,
  nonce: String,
  chain_id: Int,
) -> Result(UnsignedTransaction, TransactionError)

Create a simple ETH transfer transaction (no calldata).

Convenience wrapper around create_legacy_transaction with data set to "0x". All numeric parameters are 0x-prefixed hex strings.

pub fn create_legacy_transaction(
  to: String,
  value: String,
  gas_limit: String,
  gas_price: String,
  nonce: String,
  data: String,
  chain_id: Int,
) -> Result(UnsignedTransaction, TransactionError)

Create a new unsigned legacy (Type 0) transaction.

All numeric parameters must be 0x-prefixed hex strings. The Ethereum JSON-RPC API returns values in this format, so results from methods.get_gas_price, methods.get_transaction_count, etc. can be passed directly.

  • to - recipient address ("0x...", 40 hex chars after prefix)
  • value - amount in wei as hex (e.g. "0xde0b6b3a7640000" for 1 ETH)
  • gas_limit - gas limit as hex (e.g. "0x5208" for 21000)
  • gas_price - gas price in wei as hex
  • nonce - sender’s transaction count as hex
  • data - calldata as hex ("0x" for simple transfers)
  • chain_id - network chain ID as integer (1 for mainnet, 11155111 for Sepolia)

Examples

let assert Ok(tx) = transaction.create_legacy_transaction(
  "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
  "0xde0b6b3a7640000",  // 1 ETH in wei
  "0x5208",              // 21000 gas
  "0x3b9aca00",          // 1 gwei gas price
  "0x0",                 // nonce 0
  "0x",                  // no calldata
  1,                     // mainnet
)
pub fn error_to_string(error: TransactionError) -> String

Convert TransactionError to string

pub fn get_eip1559_transaction_hash(
  tx: SignedEip1559Transaction,
) -> String

Get transaction hash from a signed EIP-1559 transaction

pub fn get_transaction_hash(tx: SignedTransaction) -> String

Get transaction hash from a signed legacy transaction

pub const goerli_chain_id: Int

Goerli testnet chain ID

pub fn hash_raw_transaction(raw_transaction: String) -> String

Hash a raw transaction hex string to get its transaction hash

pub const mainnet_chain_id: Int

Ethereum mainnet chain ID

pub const optimism_chain_id: Int

Optimism mainnet chain ID

pub const polygon_chain_id: Int

Polygon mainnet chain ID

pub const sepolia_chain_id: Int

Sepolia testnet chain ID

pub fn sign_eip1559_transaction(
  transaction: Eip1559Transaction,
  wallet: wallet.Wallet,
) -> Result(SignedEip1559Transaction, TransactionError)

Sign an EIP-1559 (Type 2) transaction with a wallet. Produces a type-prefixed RLP-encoded raw transaction: 0x02 || RLP([…]).

pub fn sign_transaction(
  transaction: UnsignedTransaction,
  wallet: wallet.Wallet,
) -> Result(SignedTransaction, TransactionError)

Sign a legacy (EIP-155) transaction with a wallet. Produces an RLP-encoded raw transaction suitable for eth_sendRawTransaction.

pub fn signed_eip1559_transaction_to_string(
  tx: SignedEip1559Transaction,
) -> String

Convert signed EIP-1559 transaction to string for display

pub fn signed_transaction_to_string(
  tx: SignedTransaction,
) -> String

Convert signed transaction to string for display

Search Document