Trade
Transactions are cryptographically signed instructions issued by accounts. Accounts will initiate transactions to update the state of the Hash Ahead network. The simplest transaction is to transfer HAH from one account to another.
Prerequisite
To help you better understand this page, we recommend that you read Accounts and our Introduction to Hash Ahead first.
What is a transaction?
Hash Ahead transactions refer to actions initiated by externally held accounts, in other words, accounts managed by humans rather than smart contracts. For example, if Bob sends 1 HAH to Alice, Bob's account must be decreased by 1 HAH and Alice's account must be increased by 1 HAH. Transactions cause state changes.
Transactions that change the state of EVMC need to be broadcast to the entire network. Any node can broadcast a request to execute a transaction on the Hash Ahead virtual machine; thereafter, validators will execute the transaction and propagate the resulting state change to the rest of the network.
Transactions require a fee and must be included in a valid block. To make this overview more concise, we will cover gas fees and verification separately.
The submitted transaction includes the following information:
recipient– Receiving address (if it is an externally held account, the transaction will transfer the value. If it is a contract account, the transaction will execute the contract code)signature– The sender's identifier. This signature is generated when signing a transaction with the sender's private key to ensure that the sender has authorized the transaction.Nonce- a continuously incrementing counter representing the transaction number in the account.value– The amount of HAH transferred from the sender to the receiver (in Wei, a denomination of HAH)data– Optional fields that can include arbitrary datagasLimit– The maximum number of fuel units a trade can consume. Fuel units represent calculation stepsmaxPriorityFeePerGas- The maximum amount of gas to include as a validator tipmaxFeePerGas- The maximum amount of gas that is willing to pay for a transaction (includingbaseFeePerGasandmaxPriorityFeePerGas)
Gas refers to the computation required by validators to process transactions. Users have to pay for this computation. gasLimit and maxPriorityFeePerGas determine the maximum transaction fee paid to validators. More information on fuel.
The transaction object looks like this:
But the transaction object needs to be signed with the sender's private key. This proves that the transaction could only have come from the sender, and not fraudulently.
Example JSON-RPC call:
Example response:
rawIt is the RLP (Recursive Length Prefix) encoded form of the signed transaction.txis the JSON representation of the signed transaction.
If there is a signature hash, it can be cryptographically proven that the transaction came from the sender and submitted to the network.
datafield
datafieldThe vast majority of transactions are accessing contracts from externally owned accounts. Most contracts are written in the Solidity language and interpret their data fields according to the Application Binary Interface (ABI).
The first four bytes specify the function to call using the function name and a hash of the arguments. Functions can sometimes be identified based on selectors.
The rest of the call data are parameters, encoded as specified in the Application Binary Interface Specification.
Transaction Type
Hash Ahead has several different types of transactions:
Regular Transaction: A transaction from one account to another.
Contract Deployment Transaction: A transaction without a "to" address, the data field is for the contract code.
Executing Contracts: Transactions that interact with deployed smart contracts. In this case, the "to" address is the smart contract address.
About Fuel
As mentioned above, executing a transaction costs gas. A simple transfer transaction requires 21000 units of gas.
Therefore, if Bob wants to send Alice a HAH when baseFeePerGas is 190 Gwei and maxPriorityFeePerGas is 10 Gwei, Bob needs to pay the following fees:
Bob's account will be debited 1.0042 HAH (1 HAH for Alice, 0.0042 HAH for gas fee)
Alice's account will be increased by +1.0 HAH
Base fee will burn -0.00399 HAH
The verifier gets a tip of 0.000210 HAH
Any smart contract interaction also requires gas.
Any gas not spent in transactions is refunded to user accounts.
Transaction life cycle
Once the transaction is committed, the following happens:
Once you send the transaction, the cryptography generates the transaction hash:
This transaction is then broadcast to the network and included in a collection with a large number of other transactions.
Validators have to pick your transaction and include it in a block in order to validate the transaction and consider it "successful".
Over time, the block containing your transaction will be promoted to a "sound" state, and then to a "finalized" state. With these upgrades, it is further certain that your transaction has been successful and cannot be changed. Once a block is "finalized," it can only be changed through a billion-dollar attack.
\
Last updated