Skip to content

BuildDeployAccountTxn

Builds a deploy account transaction for creating new account contracts on Starknet.

Function Signature

func BuildDeployAccountTxn(
    classHash *felt.Felt,
    constructorCalldata []*felt.Felt,
    opts *BuildOptions,
) (*rpc.DeployAccountTxn, error)

Source: transactions.go

Parameters

  • classHash (*felt.Felt): Class hash of the account contract to deploy
  • constructorCalldata ([]*felt.Felt): Constructor parameters (typically public key)
  • opts (*BuildOptions): Transaction build options including salt

Returns

  • *rpc.DeployAccountTxn: Fully constructed deploy account transaction
  • error: Error if build fails

Usage Example

package main
 
import (
	"github.com/NethermindEth/juno/core/felt"
	"github.com/NethermindEth/starknet.go/utils"
)
 
func main() {
	// Account contract class hash (OpenZeppelin account, Argent, etc.)
	accountClassHash, _ := new(felt.Felt).SetString("0x...")
	
	// Public key for the account
	publicKey, _ := new(felt.Felt).SetString("0x...")
	
	// Generate salt for unique address
	salt := new(felt.Felt).SetUint64(12345)
	
	// Build deploy account transaction
	txn, err := utils.BuildDeployAccountTxn(
		accountClassHash,
		[]*felt.Felt{publicKey},
		&utils.BuildOptions{
			Salt:   salt,
			MaxFee: maxFee,
		},
	)
	
	if err != nil {
		panic(err)
	}
	
	// Precompute the account address
	accountAddress := contracts.PrecomputeAddress(
		deployerAddress,  // Usually UDC or zero address
		salt,
		accountClassHash,
		[]*felt.Felt{publicKey},
	)
	
	// txn is ready to be signed and sent
}

Use Cases

1. Deploy Standard Account

// OpenZeppelin account with single signer
txn, _ := utils.BuildDeployAccountTxn(
    ozAccountClassHash,
    []*felt.Felt{publicKey},
    &utils.BuildOptions{
        Salt:   salt,
        MaxFee: deployFee,
    },
)

2. Deploy Multi-Sig Account

// Argent multi-sig with guardian
txn, _ := utils.BuildDeployAccountTxn(
    argentClassHash,
    []*felt.Felt{ownerPublicKey, guardianPublicKey},
    &utils.BuildOptions{
        Salt:   salt,
        MaxFee: deployFee,
    },
)

3. Deploy Custom Account

// Custom account with complex constructor
customCalldata := []*felt.Felt{
    publicKey,
    threshold,
    numSigners,
}
 
txn, _ := utils.BuildDeployAccountTxn(
    customAccountClassHash,
    customCalldata,
    opts,
)

See Also