Build Transactions

Learn how to build transactions programmatically for complete control over blockchain 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.

// 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
}

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?