Build Transactions

Learn how to build transactions programmatically for complete control over network interactions.

Objectives

  • Build signed transactions for immediate broadcast

  • Create unsigned transactions for multi-signature workflows

  • Implement sponsored transactions to pay fees for users

Transaction types

Stacks supports five primary transaction types, each serving a specific purpose. Three of the five primary transaction types will be commonly used amongst developers.

// STX Transfer - Send native tokens
const stxTransfer = await makeSTXTokenTransfer(options);

// Contract Deployment - Deploy Clarity contracts  
const deployment = await makeContractDeploy(options);

// Contract Call - Execute contract functions
const contractCall = await makeContractCall(options);

// Each transaction type accepts similar base options:
interface TransactionOptions {
  senderKey: string;        // Private key for signing
  network: string;          // 'mainnet' or 'testnet'
  fee?: bigint;            // Manual fee in microSTX
  nonce?: bigint;          // Manual nonce
  anchorMode?: AnchorMode; // Block anchoring strategy
}

StacksTransactionWire is the low-level transaction class that represents a Stacks transaction in its exact wire (on-chain) format. It is responsible for constructing, signing, verifying, and serializing transactions exactly as they are transmitted over the network and validated by Stacks nodes.

Building signed transactions

Signed transactions are ready to broadcast immediately. The private key signs during creation.

1

STX token transfer

2

Smart contract deployment

3

Contract function calls

Unsigned transactions

Create unsigned transactions for multi-signature workflows or offline signing.

Let one account pay fees for another account's transaction.

Multi-signature transactions

Require multiple signatures for enhanced security.

Working with Clarity values

Use the Cl helper for type-safe contract arguments.

Post-conditions

Add safety constraints to protect users from unexpected transfers.

Fee estimation

Get accurate fee estimates before broadcasting.

Last updated

Was this helpful?