Skip to content

TransactionHashDeployAccount

Calculates the transaction hash for a deploy account transaction.

Method Signature

func (account *Account) TransactionHashDeployAccount(
	tx rpc.DeployAccountType,
	contractAddress *felt.Felt,
) (*felt.Felt, error)

Parameters

  • tx - Deploy account transaction
  • contractAddress - Precomputed contract address

Returns

  • *felt.Felt - Transaction hash
  • error - Error if hash calculation fails

Usage Example

Prerequisites: This example assumes you have an account instance already created. To learn how to create an account, see NewAccount.

package main
 
import (
	"fmt"
	"log"
 
	"github.com/NethermindEth/juno/core/felt"
	"github.com/NethermindEth/starknet.go/account"
	"github.com/NethermindEth/starknet.go/rpc"
)
 
func main() {
	// Assuming 'acc' is your Account instance
	var acc *account.Account
	// acc = ... (already initialized)
 
	// Create a deploy account transaction V1
	classHash, _ := new(felt.Felt).SetString("0x04c6d6cf894f8bc96bb9c525e6853e5483177841f7388f74a46cfda6f028c755")
	contractAddressSalt, _ := new(felt.Felt).SetString("0x04a7a67901e7f64e7d4f46fa17a0c57aefb0e91b3ec31e83feb758ae56b6e29e")
	pubKey, _ := new(felt.Felt).SetString("0x03603a2692a2ae60abb343e832ee53b55d6b25f02a3ef1565ec691edc7a209b2")
 
	deployAccountTx := rpc.DeployAccountTxnV1{
		Type:                rpc.TransactionTypeDeployAccount,
		MaxFee:              new(felt.Felt).SetUint64(1000000000000),
		Version:             rpc.TransactionV1,
		Signature:           []*felt.Felt{},
		Nonce:               new(felt.Felt).SetUint64(0),
		ClassHash:           classHash,
		ContractAddressSalt: contractAddressSalt,
		ConstructorCalldata: []*felt.Felt{pubKey},
	}
 
	// Precompute the contract address (required for deploy account hash)
	precomputedAddress, _ := new(felt.Felt).SetString("0x04a7a67901e7f64e7d4f46fa17a0c57aefb0e91b3ec31e83feb758ae56b6e29e")
 
	// Calculate transaction hash
	txHash, err := acc.TransactionHashDeployAccount(&deployAccountTx, precomputedAddress)
	if err != nil {
		log.Fatalf("Error calculating hash: %v", err)
	}
 
	fmt.Printf("Transaction hash: %s\n", txHash)
}

Expected Output

Transaction hash: 0x30404dd09741e3e8450579b3f992dbb20cf1d13207defa89a3549f7305bd97f

Description

TransactionHashDeployAccount calculates the hash for deploy account transactions using the precomputed address.

Error Handling

hash, err := acc.TransactionHashDeployAccount(tx, contractAddress)
if err != nil {
	// Handle errors like:
	// - Invalid transaction type
	// - Hash calculation failure
	return err
}

Related Methods