PrecomputeAccountAddress
Calculates the deterministic address for an account contract before deployment.
Function Signature
func PrecomputeAccountAddress(
salt *felt.Felt,
classHash *felt.Felt,
constructorCalldata []*felt.Felt,
) *felt.FeltParameters
salt- Random value for address generationclassHash- Class hash of the account contractconstructorCalldata- Parameters passed to the constructor
Returns
*felt.Felt- Precomputed account address
Usage Example
package main
import (
"fmt"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/account"
)
func main() {
// Create a salt for the account address
salt, _ := new(felt.Felt).SetString("0x12345678")
// Use a standard account class hash (OpenZeppelin account contract)
classHash, _ := new(felt.Felt).SetString("0x061dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f")
// Constructor calldata - typically the public key for an account
publicKey, _ := new(felt.Felt).SetString("0x01234567890abcdef01234567890abcdef01234567890abcdef01234567890ab")
constructorCalldata := []*felt.Felt{publicKey}
// Precompute the account address
address := account.PrecomputeAccountAddress(salt, classHash, constructorCalldata)
fmt.Printf("Precomputed account address: %s\n", address)
// Test with empty constructor calldata
fmt.Println("\nWith empty constructor calldata:")
addressEmpty := account.PrecomputeAccountAddress(salt, classHash, []*felt.Felt{})
fmt.Printf("Precomputed account address: %s\n", addressEmpty)
// Test with different salt
salt2, _ := new(felt.Felt).SetString("0x87654321")
address2 := account.PrecomputeAccountAddress(salt2, classHash, constructorCalldata)
fmt.Printf("\nWith different salt (0x87654321):\nPrecomputed account address: %s\n", address2)
}Expected Output
Precomputed account address: 0x24704c7725da38273659643fd01b9daa6b3811bfbf9ded39f05c02b6fa68a1f
With empty constructor calldata:
Precomputed account address: 0x50486d52f752622fce6cc467812a33151c1fe19d80dbaac5997c692a8dc5ed2
With different salt (0x87654321):
Precomputed account address: 0x597c5caf6ef950f84aa0af703352969b88ba10bf0e2d63342622b7c06a33862Description
PrecomputeAccountAddress calculates the deterministic address where an account contract will be deployed. This is essential for the account deployment flow:
- Precompute the account address
- Fund that address with tokens (for fees)
- Deploy the account contract
- The contract deploys to the precomputed address
The address is calculated using the same algorithm as Starknet's contract address computation.
Error Handling
This function does not return errors. It always produces a valid address from the provided parameters.
// Ensure inputs are valid
if salt == nil || classHash == nil {
log.Fatal("Salt and class hash must not be nil")
}
address := account.PrecomputeAccountAddress(salt, classHash, constructorCalldata)
// Safe to use addressRelated Methods
- BuildAndEstimateDeployAccountTxn - Uses this function internally
- NewAccount - Create account instance after deployment

