Transaction types
Starknet supports the following types of transactions:
-
invoke transaction
-
declare transaction
-
deploy_account transaction
This topic describes the available fields for these transaction types and how each transaction hash is calculated.
The |
Transaction versioning
Starknet supports the transaction versions described here.
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.
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. |
Deploy transaction hash calculation
In order to calculate the transaction hash, we first need to obtain the deployed contract address. The Deploy transaction’s hash is calculated as follows:
Where:
-
The placeholder zero is used to align the hash computation for the different types of transactions.
-
“deploy” and “constructor” are constant strings encoded in ASCII.
-
\(h\) is the Pedersen hash and \(sn\_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.
Invoke Transaction
The invoke transaction is the main transaction type used to invoke contract functions in Starknet.
Invoke transaction version 0 is deprecated and will be removed in a future release of Starknet. |
Invoke v1
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 hash calculation
The invoke
v1 transaction hash is calculated as a hash over the given transaction elements,
specifically:
Where:
-
\(\text{invoke}\) is a constant prefix string, encoded in ASCII.
-
The placeholder zero is used to align the hash computation for the different types of transactions.
-
\(\text{chain_id}\) is a constant value that specifies the network to which this transaction is sent. See Chain-Id.
-
\(h\) is the Pedersen hash
Deprecated features
Declare transaction
The declare transaction is used to introduce new classes into the state of Starknet, enabling other contracts to deploy instances of those classes or using them in a library call. For more information, see contract classes.
Declare v0 is no longer supported. v1 used to declare Cairo 0 classes are deprecated and will be removed in a future Starknet version. New Cairo 1.0 classes can only be declared via the declare v2 transaction. |
Declare v2
Name | Type | Description |
---|---|---|
|
|
The (Cairo 1.0) class. |
|
|
The hash of the compiled class (see here for more information) |
|
|
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. The value is 1. |
v2 hash calculation
The hash of a v2 declare transaction is computed as follows:
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 which is currently used in Starknet
Deprecated features
Declare v1
These old versions used to declare Cairo 0 classes are deprecated and will be removed in a future Starknet version. |
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 hash calculation
The hash of a v1 declare transaction is computed as follows:
Where:
-
\(\text{declare}\) is a constant prefix string, encoded in ASCII.
-
\(\text{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.
-
\(\text{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 hash calculation
The hash of a v0 declare transaction is computed as follows:
Where:
-
\(\text{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.
-
\(\text{class_hash}\) is the hash of the contract class. See Class Hash for details about how the hash is computed.
-
\(\text{chain_id}\) is a constant value that specifies the network to which this transaction is sent. See Chain-Id.
-
\(h\) is the Pedersen hash
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 would-be account address so that you could pay the
transaction fee (see here for more details)
. You can then send the deploy_account
transaction.
A deploy_account
transaction has the following 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. |
Deploy account hash calculation
The hash of a deploy_account
transaction is computed as follows:
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
Starknet currently supports three chain IDs. 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)
Three constants are currently used:
-
SN_MAIN
for Starknet’s main network. -
SN_GOERLI
for Starknet’s public testnet. -
SN_GOERLI2
for Starknet developers.