Sep 29 , 2020

What are Ethereum Transactions?

Transaction Types and Data Model

Understanding the anatomy of a transaction is pivotal for success in Ethereum development.

Transaction Data Model

  • Nonce: Transaction counter of the sender
  • Gas Price: Price paid per unit of gas
  • Gas Limit: Maximum gas provided for the transaction
  • To: Recipient address or contract address
  • Value: Amount of ether sent in the transaction
  • Data: Input data for contract transactions
  • v, r, s: Components of the transaction signature

Example:

{
from: "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8",
to: "0xac03bb73b6a9e108530aff4df5077c2b3d481e5a",
gasLimit: "21000",
maxFeePerGas: "300",
maxPriorityFeePerGas: "10",
nonce: "0",
value: "10000000000",
data: null,
}

Types of Transactions

Value Transfer

  • Gas Limit: Typically 21,000
  • Description: Transfer ether from one account to another.
  • Details: Doesn't modify the blockchain's state. Recipients can be Externally Owned Accounts (EOA) or Contracts.

Contract Deployment

  • Description: Deploy a new smart contract onto the blockchain.
  • Details: Requires transaction data to contain the bytecode of the contract being deployed.

Function Call

  • Description: Invoke a function within a deployed contract.
  • Details: Can modify the state of the blockchain. These transaction types and their associated data models are crucial for executing different operations on the Ethereum blockchain, managing smart contracts, and transferring ether between accounts.

ABI Encoding

  • To encode function calls to send to smart contracts, expecting those smart contract to interpret that message and consequently run the code you want.
  1. Account to Contract
  2. Contract to Contract
    • Contract can call other contracts in 2 ways: a) A.foo(x, y, z) b) use the low-level call (not recommended)

Caller:

  • mutable arguments
  • encode arguments
  • what are callee's apis? a) The Function Signature b) The Function Selector
    • first 4 bytes of function signature
    • how to get?
      • The first 4 bytes returned from abi.encodeWithSignature(....) is the function selector.

addr.call(abi.encodeWithSignature("transfer(address,uint256)", 0xSomeAddress, 123))

contract FunctionSelector {
/*
"transfer(address,uint256)"
0xa9059cbb
"transferFrom(address,address,uint256)"
0x23b872dd
*/
function getSelector(string calldata _func) external pure returns (bytes4) {
return bytes4(keccak256(bytes(_func)));
}
}

Callee:

  • immutable calldata
  • decode calldata
  • how can caller call me? a) The Function Selector b) The Function Arguments

Shout Outs:

  1. https://ethereum.org/en/developers/docs/transactions/
  2. https://learnevm.com/chapters/intro/overview
  3. https://solidity-by-example.org/
  4. https://soliditylang.org/

Thanks for reading! If you want to see future content, you can follow me on Twitter or get connected over at LinkedIn.


Support My Content

If you find my content helpful, consider supporting a humanitarian cause (building homes for elderly people in rural Terai region of Nepal) that I am planning with your donation:

Ethereum (ETH)

0xb0b1B20062DA9Dd7BaA4D5b088DF49dbe4b46fF2

Thank you for your support!