Transaction Hash Functions
Transaction hash functions calculate unique identifiers for Starknet transactions. Each transaction type and version has its own hash calculation method following the Starknet specification.
For conceptual understanding of transaction hashing, see Transaction Hashing Concepts.
Quick Reference
Use this table to find the right hash function for your transaction:
| Transaction Type | Version | Function | Hash Algorithm | Fee Model |
|---|---|---|---|---|
| Invoke | V0 (deprecated) | TransactionHashInvokeV0 | Pedersen | max_fee |
| Invoke | V1 | TransactionHashInvokeV1 | Pedersen | max_fee |
| Invoke | V3 (current) | TransactionHashInvokeV3 | Poseidon | resource_bounds |
| Declare | V1 | TransactionHashDeclareV1 | Pedersen | max_fee |
| Declare | V2 | TransactionHashDeclareV2 | Pedersen | max_fee |
| Declare | V3 (current) | TransactionHashDeclareV3 | Poseidon | resource_bounds |
| Deploy Account | V1 | TransactionHashDeployAccountV1 | Pedersen | max_fee |
| Deploy Account | V3 (current) | TransactionHashDeployAccountV3 | Poseidon | resource_bounds |
Version Comparison
V0/V1/V2 Transactions (Legacy)
Hash Function: Pedersen hash
Fee Model: Single max_fee field
These versions are deprecated but still supported for historical transactions:
- V0: Original invoke format (deprecated)
- V1: Added nonce and account abstraction support
- V2: Added compiled class hash for Declare transactions
V3 Transactions (Current Standard)
Hash Function: Poseidon hash
Fee Model: resource_bounds with separate limits
V3 introduces modern features:
- Resource Bounds: Separate limits for L1 gas, L2 gas, and L1 data gas
- Data Availability Modes: Control where fee and nonce data is stored (L1 vs L2)
- Tip: Optional priority fee for faster inclusion
- PayMaster Support: Third-party fee payment capability
- Poseidon Hashing: More efficient than Pedersen
Migration Note: For new applications, always use V3 transactions. V0/V1/V2 support is maintained for compatibility only.
Usage Patterns
Pattern 1: Calculate Hash for Existing Transaction
When you have a transaction object and need its hash:
// For V3 Invoke transaction
txHash, err := hash.TransactionHashInvokeV3(invokeV3Txn, chainID)
if err != nil {
log.Fatal("Failed to calculate hash:", err)
}Pattern 2: Verify Transaction Hash
When verifying a transaction matches the expected hash:
// Calculate hash from transaction data
calculatedHash, _ := hash.TransactionHashInvokeV3(txn, chainID)
// Compare with received hash
if !calculatedHash.Equal(receivedHash) {
log.Fatal("Transaction hash mismatch")
}Pattern 3: Pre-calculate Hash for Signing
Account signing methods calculate the hash internally, but you can pre-calculate for verification:
// Pre-calculate hash
txHash, _ := hash.TransactionHashInvokeV3(txn, chainID)
// Later during signing, the account will calculate the same hash
signature, _ := account.Sign(ctx, txHash)Function Categories
Invoke Transaction Hashes
Execute contract functions:
- TransactionHashInvokeV0 - Deprecated V0 format
- TransactionHashInvokeV1 - Legacy with nonce
- TransactionHashInvokeV3 - Current standard with resource bounds
Declare Transaction Hashes
Register new contract classes:
- TransactionHashDeclareV1 - Legacy Cairo 0 contracts
- TransactionHashDeclareV2 - Sierra contracts with compiled hash
- TransactionHashDeclareV3 - Current standard with resource bounds
Deploy Account Transaction Hashes
Create new account contracts:
- TransactionHashDeployAccountV1 - Legacy deployment
- TransactionHashDeployAccountV3 - Current standard with resource bounds
Utility Functions
Low-level helpers:
- CalculateDeprecatedTransactionHashCommon - Internal utility for V0/V1/V2 hashes
Common Parameters
All transaction hash functions require:
- Transaction Object: The specific transaction type (InvokeTxnV3, DeclareTxnV2, etc.)
- Chain ID: Network identifier (use
SN_MAIN,SN_SEPOLIA, or custom for devnet)
Some functions (Deploy Account) also require:
- Contract Address: Pre-computed address for the account being deployed
Error Handling
All functions validate required parameters and return descriptive errors:
txHash, err := hash.TransactionHashInvokeV3(txn, chainID)
if err != nil {
// Check for specific error types
if err == hash.ErrNotAllParametersSet {
log.Fatal("Transaction missing required fields")
}
log.Fatal("Hash calculation failed:", err)
}
// Safe to use txHashChain ID Values
Common chain IDs for hash calculation:
// Mainnet
chainID := new(felt.Felt).SetBytes([]byte("SN_MAIN"))
// Sepolia testnet
chainID := new(felt.Felt).SetBytes([]byte("SN_SEPOLIA"))
// Devnet (example)
chainID := new(felt.Felt).SetBytes([]byte("SN_DEVNET"))Related Documentation
- Transaction Hashing Concepts - Understand hash calculation principles
- Class Hash Functions - Calculate contract class hashes
- Account Signing Methods - Use transaction hashes for signing
- RPC Transaction Methods - Submit transactions with calculated hashes
Specifications
All hash functions follow official Starknet specifications:
- Transaction Hash Specification
- SNIP-8: Resource Bounds - V3 transaction format

