Transaction types
Starknet supports the following types of transactions, as defined in the Starknet API:
DECLARE
|
Declares new contract classes, enabling new contract instances. |
INVOKE
|
Invokes an existing function in a contract. |
DEPLOY_ACCOUNT
|
Deploys new account contracts in smart wallets. |
To see how these transaction types appear in the Starknet API, see starknet_api_openrpc.json.
This topic describes the available fields for these transaction types and how each transaction’s hash is calculated.
Transaction versions
When the fields that comprise a transaction change, either with the addition of a new field or the removal of an existing field, then the transaction version increases.
Deprecated transaction versions are still supported, but support will be removed in a future release of Starknet.
Transaction name | Current version | Deprecated versions | Unsupported versions |
---|---|---|---|
|
v3 |
v1, v0 |
N/A |
|
v3 |
v2, v1 |
v0 |
|
v3 |
v1 |
N/A |
|
N/A |
N/A |
v0 |
Additionally, see information on the L1 handler transaction type.
Do not submit a transaction that uses an unsupported transaction type, because it cannot be included in a proof, and so cannot become part of a Starknet block. |
While the |
INVOKE
transaction
The INVOKE
transaction type invokes a function in an existing contract instance. The contract code of the account that sends the INVOKE
transaction determines how to process the transaction.
Because an account’s |
Every INVOKE
transaction in Starknet undergoes the validation and execution stages, initiated by the __validate__
and __execute__
functions. The validation stage verifies that the account that sent the transaction approves it.
v3 transaction fields
Field name | Type | Description | ||
---|---|---|---|---|
|
|
For future use. Currently this value is always empty. For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
The arguments that are passed to the validate and execute functions. |
||
|
|
The id of the chain to which the transaction is sent. |
||
|
|
For future use. Currently this value is always For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
The transaction nonce. |
||
|
|
For future use. Currently this value is always For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
For future use. Currently this value is always empty. For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
Used for enabling the fee market. A dictionary that maps resource type to resource bounds. The resource is the amount of L1 or L2 gas used to pay for the transaction.
|
||
|
|
The address of the account initiating the transaction. |
||
|
|
Additional information given by the sender, used to validate the transaction. |
||
|
|
For future use. Currently this value is always |
||
|
|
The transaction’s version. Transaction version, where
|
v3 hash calculation
The INVOKE
v3 transaction hash is calculated as a Poseidon hash over the given transaction elements,
specifically:
invoke_v3_tx_hash = h( "invoke", version, sender_address, h(tip, l1_gas_bounds, l2_gas_bounds), h(paymaster_data), chain_id, nonce, data_availability_modes, h(account_deployment_data), h(calldata) )
Where:
-
invoke
is a constant prefix string, encoded in ASCII. -
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
l1_gas_bounds
is constructed as follows:\[\underbrace{\text{L1_GAS}}_{\text{60 bits}} | \underbrace{\text{max_amount}}_{\text{64 bits}} | \underbrace{\text{max_price_per_unit}}_{\text{128 bits}}\] -
l2_gas_bounds
is constructed as follows:\[\underbrace{\text{L2_GAS}}_{\text{60 bits}} | \underbrace{\text{max_amount}}_{\text{64 bits}} | \underbrace{\text{max_price_per_unit}}_{\text{128 bits}}\] -
data_availability_modes
is a concatenation offee_data_availability_mode
andnonce_data_availability_mode
, as follows:\[\underbrace{0\cdots0}_{\text{188 bits}} | \underbrace{\text{nonce_data_availability_mode}}_{\text{32 bits}} | \underbrace{\text{fee_data_availability_mode}}_{\text{32 bits}}\] -
h
is the Poseidon hash.
v1 (deprecated) transaction fields
Name | Type | Description |
---|---|---|
|
|
The address of the sender of this transaction. |
|
|
The arguments that are passed to the |
|
|
Additional information given by the sender, used to validate the transaction. |
|
|
The maximum fee that the sender is willing to pay for the transaction |
|
|
The transaction nonce. |
|
|
The transaction’s version. The value is 1. |
v1 (deprecated) hash calculation
The INVOKE
v1 transaction hash is calculated as a hash over the given transaction elements,
specifically:
invoke_v1_tx_hash = h( "invoke", version, sender_address, 0, h(calldata), max_fee, chain_id, nonce )
Where:
DECLARE
transaction
The DECLARE
transaction introduces new contract classes into the state of Starknet, enabling other contracts to deploy instances of those classes or use them in a library call. For more information, see contract classes.
v3 transaction fields
Field name | Type | Description | ||
---|---|---|---|---|
|
|
For future use. Currently this value is always empty. For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
The id of the chain to which the transaction is sent. |
||
|
|
The hash of the compiled class. For more information, see Class hash. |
||
|
|
The class definition. For more information, see Class hash. |
||
|
|
For future use. Currently this value is always For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
The transaction nonce. |
||
|
|
For future use. Currently this value is always For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
For future use. Currently this value is always empty. For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
Used for enabling the fee market. A dictionary that maps resource type to resource bounds. The resource is the amount of L1 or L2 gas used to pay for the transaction.
|
||
|
|
The address of the account initiating the transaction. |
||
|
|
Additional information given by the sender, used to validate the transaction. |
||
|
|
For future use. Currently this value is always |
||
|
|
The transaction’s version. Transaction version, where
|
v3 hash calculation
The hash of a v3 DECLARE
transaction is computed as follows:
declare_v3_tx_hash = h( "declare", version, sender_address, h(tip, l1_gas_bounds, l2_gas_bounds), h(paymaster_data), chain_id, nonce, data_availability_modes, h(account_deployment_data), class_hash, compiled_class_hash )
Where:
-
declare
is a constant prefix string, encoded in ASCII. -
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
l1_gas_bounds
is constructed as follows:\[\underbrace{\text{L1_GAS}}_{\text{60 bits}} | \underbrace{\text{max_amount}}_{\text{64 bits}} | \underbrace{\text{max_price_per_unit}}_{\text{128 bits}}\] -
l2_gas_bounds
is constructed as follows:\[\underbrace{\text{L2_GAS}}_{\text{60 bits}} | \underbrace{\text{max_amount}}_{\text{64 bits}} | \underbrace{\text{max_price_per_unit}}_{\text{128 bits}}\] -
data_availability_modes
is a concatenation offee_data_availability_mode
andnonce_data_availability_mode
, as follows:\[\underbrace{0\cdots0}_{\text{188 bits}} | \underbrace{\text{nonce_data_availability_mode}}_{\text{32 bits}} | \underbrace{\text{fee_data_availability_mode}}_{\text{32 bits}}\] -
h
is the Poseidon hash. -
class_hash
is the hash of the contract class. See Class Hash for details about how the hash is computed -
compiled_class_hash
is the hash of the compiled class generated by the Sierra→Casm compiler that is used in Starknet
v2 (deprecated) transaction fields
Name | Type | Description |
---|---|---|
|
|
The id of the chain to which the transaction is sent. |
|
|
The (Cairo 1.0) class. |
|
|
The hash of the compiled class (see here for more information) |
|
|
The address of the account initiating the transaction. |
|
|
Additional information given by the sender, used to validate the transaction. |
|
|
The maximum fee that the sender is willing to pay for the transaction. |
|
|
The transaction nonce. |
|
|
The transaction’s version. The value is 2. |
v2 (deprecated) hash calculation
The hash of a v2 DECLARE
transaction is computed as follows:
declare_v2_tx_hash = h( "declare", version, sender_address, 0, h(class_hash), max_fee, chain_id, nonce, compiled_class_hash )
Where:
-
h
is the Poseidon hash function -
class_hash
is the hash of the contract class. See Class Hash for details about how the hash is computed -
compiled_class_hash
is the hash of the compiled class generated by the Sierra→Casm compiler that is used in Starknet
v1 (deprecated) transaction fields
This transaction version was used to declare Cairo 0 classes.
Name | Type | Description |
---|---|---|
|
|
The class object. |
|
|
The address of the account initiating the transaction. |
|
|
The maximum fee that the sender is willing to pay for the transaction. |
|
|
Additional information given by the sender, used to validate the transaction. |
|
|
The transaction nonce. |
|
|
The transaction’s version. Possible values are 1 or 0. |
v1 (deprecated) hash calculation
The hash of a v1 DECLARE
transaction is computed as follows:
declare_v1_tx_hash = h( "declare", version, sender_address, 0, h(class_hash), max_fee, chain_id, nonce )
Where:
-
declare
is a constant prefix string, encoded in ASCII. -
class_hash
is the hash of the contract class. See Class Hash for details about how the hash is computed. -
The placeholder zero is used to align the hash computation for the different types of transactions.
-
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
h
is the Pedersen hash
v0 (unsupported) hash calculation
This transaction version was used to declare Cairo 0 classes.
The hash of a v0 DECLARE
transaction is computed as follows:
declare_v0_tx_hash = h( "declare", version, sender_address, 0, h(), max_fee, chain_id, class_hash )
Where:
-
declare
is a constant prefix string, encoded in ASCII. -
The placeholder zeros are used to align the hash computation for the different types of transactions.
-
h
is the Pedersen hash -
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
class_hash
is the hash of the contract class. See Class Hash for details about how the hash is computed.
DEPLOY_ACCOUNT
transaction
Since StarkNet v0.10.1 the DEPLOY_ACCOUNT
transaction replaces the DEPLOY
transaction
for deploying account contracts.
To use it, you should first pre-fund your new account address so that you can pay the
transaction fee. You can then send the DEPLOY_ACCOUNT
transaction.
For more information, see Deploying a new account.
v3 transaction fields
Field name | Type | Description | ||
---|---|---|---|---|
|
|
The id of the chain to which the transaction is sent. |
||
|
|
The hash of the desired account class. For more information, see Class hash. |
||
|
|
The arguments to the account constructor. |
||
|
|
A random salt that determines the account address. |
||
|
|
For future use. Currently this value is always For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
The transaction nonce. |
||
|
|
For future use. Currently this value is always For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
For future use. Currently this value is always empty. For more information, see SNIP 8: Transaction V3 Structure |
||
|
|
Used for enabling the fee market. A dictionary that maps resource type to resource bounds. The resource is the amount of L1 or L2 gas used to pay for the transaction.
|
||
|
|
Additional information given by the sender, used to validate the transaction. |
||
|
|
For future use. Currently this value is always |
||
|
|
The transaction’s version. Transaction version, where
|
v3 hash calculation
The hash of a DEPLOY_ACCOUNT
transaction is computed as follows:
deploy_account_v3_tx_hash = h( "deploy_account", version, contract_address, h(tip, l1_gas_bounds, l2_gas_bounds), h(paymaster_data), chain_id, nonce, data_availability_modes, h(constructor_calldata), class_hash, contract_address_salt )
Where:
-
deploy_account
is a constant prefix string, encoded in ASCII. -
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
l1_gas_bounds
is constructed as follows:\[\underbrace{\text{L1_GAS}}_{\text{60 bits}} | \underbrace{\text{max_amount}}_{\text{64 bits}} | \underbrace{\text{max_price_per_unit}}_{\text{128 bits}}\] -
l2_gas_bounds
is constructed as follows:\[\underbrace{\text{L2_GAS}}_{\text{60 bits}} | \underbrace{\text{max_amount}}_{\text{64 bits}} | \underbrace{\text{max_price_per_unit}}_{\text{128 bits}}\] -
data_availability_modes
is a concatenation offee_data_availability_mode
andnonce_data_availability_mode
, as follows:\[\underbrace{0\cdots0}_{\text{188 bits}} | \underbrace{\text{nonce_data_availability_mode}}_{\text{32 bits}} | \underbrace{\text{fee_data_availability_mode}}_{\text{32 bits}}\] -
h
is the Poseidon hash. -
class_hash
is the hash of the contract class. See Class Hash for details about how the hash is computed. -
contract_address
is the address of the newly deployed account. For information on how this address is calculated, see Contract address.
v1 (deprecated) transaction fields
Name | Type | Description |
---|---|---|
|
|
The hash of the desired account class. |
|
|
The arguments to the account constructor. |
|
|
A random salt that determines the account address. |
|
|
Additional information given by the sender, used to validate the transaction. |
|
|
The maximum fee that the sender is willing to pay for the transaction |
|
|
The transaction nonce. |
|
|
The transaction’s version. The value is 1. |
v1 (deprecated) hash calculation
The hash of a DEPLOY_ACCOUNT
transaction is computed as follows:
deploy_account_v1_tx_hash = h( "deploy_account", version, contract_address, 0, h(class_hash, contract_address_salt, constructor_calldata), max_fee, chain_id, nonce )
Where:
-
deploy_account
is a constant prefix string, encoded in ASCII. -
The placeholder zero is used to align the hash computation for the different types of transactions.
-
h
is the Pedersen hash -
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
class_hash
is the hash of the contract class. See Class Hash for details about how the hash is computed.
DEPLOY
(unsupported) transaction hash calculation
If you need to retrieve the hash of an existing DEPLOY
transaction, you can use this information to calculate the hash of the transaction.
Before you can calculate the transaction hash, get the deployed contract address. The DEPLOY
transaction’s hash is calculated as shown in the following pseudo code:
deploy_tx_hash = h( "deploy", version, contract_address, sn_keccak("constructor"), h constructor_calldata), 0, chain_id )
Where:
-
The placeholder zero is used to align the hash computation for the different types of transactions.
-
deploy
andconstructor
are constant strings encoded in ASCII. -
h
is the Pedersen hash andsn_keccak
is Starknet Keccak. -
chain_id
is a constant value that specifies the network to which this transaction is sent. See Chain-Id. -
contract_address
is calculated as described here.
Signature
While Starknet does not have a specific signature scheme built into the protocol, the Cairo language, in which smart contracts are written, does have an efficient implementation for ECDSA signature with respect to a STARK-friendly curve.
The generator used in the ECDSA algorithm is \(G=\left(g_x, g_y\right)\) where:
\(g_x=874739451078007766457464989774322083649278607533249481151382481072868806602\) \(g_y=152666792071518830868575557812948353041420400780739481342941381225525861407\)
Chain ID
Chain IDs are given as numbers, representing the ASCII encoding of specific constant strings, as illustrated by the following Python snippet:
chain_id = int.from_bytes(value, byteorder="big", signed=False)
The following constants are currently used. They correspond to the chain IDs that Starknet currently supports:
-
SN_MAIN
for Starknet’s main network. -
SN_SEPOLIA
for Starknet’s public testnet on Sepolia.