Build an unsigned transaction
Create unsigned transactions for hardware wallets or multi-signature scenarios
import { getPublicKeyFromPrivate } from "@stacks/encryption";import {makeUnsignedSTXTokenTransfer,makeUnsignedContractCall,Cl,AnchorMode,PostConditionMode} from "@stacks/transactions";import { STACKS_TESTNET } from "@stacks/network";// Get public key from private keyconst privateKey = "753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601";const publicKey = getPublicKeyFromPrivate(privateKey);// Build unsigned STX transferconst unsignedTx = await makeUnsignedSTXTokenTransfer({recipient: "ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5",amount: 1000000n, // 1 STX in micro-STXfee: 200n,nonce: 0n,network: STACKS_TESTNET,memo: "Test transfer",publicKey,anchorMode: AnchorMode.Any,postConditionMode: PostConditionMode.Deny,});// Transaction is ready for external signingconsole.log("Unsigned transaction created:", unsignedTx.txid());
Use cases
- Hardware wallet integration (Ledger, Trezor)
- Multi-signature wallet transactions
- Offline transaction signing
- Secure key management systems
Key concepts
Unsigned transactions separate transaction creation from signing:
- Public key only: No private key needed for creation
- External signing: Sign with hardware wallet or secure enclave
- Serialization: Can be transported and signed elsewhere