Overview
Transactions are cryptographically signed instructions from accounts that update the state of the Starknet network. Starknet supports only three types of transactions, with each type going through the same lifecycle to receive its execution and finality statuses. Every transaction that was executed successfully is issued a receipt, which includes its statuses, as well as other information about it. Additional information- Transaction fields and hash calculations reference in References
starknet_api_openrpc.jsonin thestarknet-specsGitHub repository
Transaction types
Starknet supports the following types of transactions:The
L1HandlerTransaction type is also a valid transaction type within Starknet, be it cannot be broadcast through the Starknet API like other transaction types, as it was specifically designed for internal Starknet operations (particularly, handling messages from L1 to L2).The DEPLOY transaction type existed in Starknet for deploying account before being replaced by DEPLOY_ACCOUNT. DEPLOY only had one version (v0) and is now unsupported by Starknet.Transaction lifecycle
The high-level steps in the Starknet transaction lifecycle are as follows:- Transaction submission: A transaction is submitted to a sequencer by a full node.
- Mempool validation: The sequencer’s mempool performs preliminary validation of the transaction, such as ensuring that its invoker’s balance exceeds the transaction’s
max_feevalue, assuring the transaction’s calldata length is within the legal limit, and more. If the transaction is invalid, it does not proceed. - Sequencer validation: The sequencer performs preliminary validation of the transaction before executing it to ensure that the transaction is still valid. If the transaction is invalid, it does not proceed.
- Execution: The sequencer batches all transactions that passed the preliminary validation into a block, and applies them to the state sequentially. If a transaction fails during execution, it is included in the block with as reverted.
- Proof generation and verification: The prover uses the Starknet operating system to computes the proof for the correct execution of all transactions in the block, and transmits it to the L1 verifier, which verifies it. At this point, the L1 state is updated to include the transaction.
Mempools
Up to and including Starknet v0.13.5, transactions were received and ordered by the sequencer in a first-in-first-out (FIFO) fashion. Starting from Starknet v0.14.0, each sequencer will instead maintain a mempool, decouping the transaction order of arrival from the transaction ordering in blocks, for which they are can decide their own policy. The introduction of mempools will have the following implications on how transactions are processed:-
Nonces: Transactions with a nonce greater than the sender’s current nonce + will be rejected by the mempool, where:
- A sender’s current nonce is the sender’s nonce in the latest finalized state at the time the transaction is received
- X is 200 for
INVOKEandDEPLOY_ACCOUNTtransactions and forDECLAREtransactions (i.e., no declares with future nonces)
-
Fee escalation: A transaction in the mempool can be replaced by a transaction sent from the same account with the same nonce and both
tipandmax_l2_gas_priceincreased by at least 10%. If the transaction was submitted with zero tip, it can still be replaced by another transaction with zero tip.There are unlikely edge cases in which a transaction is not replaced despite submitting a valid transaction to replace it, such as the existing transaction entering a block while the new one is still processed in the gateway. - Transaction time-to-live (TTL): Transactions that cannot be included in a block and have exceeded their TTL, currently configured to be 5 mins, are periodically evicted from the mempool
-
DECLARE transactions time-to-mature (TTM): Before being inserted into the mempool,DECLAREtransactions are sent to a “waiting room” until they exceed their TTM, where TTM < TTL but is still TBD. While in the “waiting room”,DECLAREtransactions can’t be replaced, and transactions sent with the same nonce as a transaction in the “waiting room” by the same account are rejected
Transaction statuses
Since Starknet version 0.14.0, the finality statuses are the following:State implications of reverted transactions
When a transaction is marked asREVERTED, the following state implications occur:
Transaction receipt
A transaction receipt can be obtained by using the Starknet API’sstarknet_getTransactionReceipt endpoint and contains the following fields:
The following is an example of a transaction receipt: