BlockchainJun 15, 20264 min read

Auto-Select Inputs, Change, and Fees: How the Wallet Builds a Complete Transaction for You

When using the high-level SDK, the wallet automatically selects spendable UTXOs, generates change outputs, and calculates fees. This article explains how this process works, its benefits, and potential risks.

Ethan Lin

Ethan Lin

technical_editor

Share

At a Glance

When you call WalletClient.createAction(), the wallet can automatically select spendable inputs, generate a change output, and calculate the fee. This is where the high-level SDK provides the most value for beginners: you describe the desired outputs, and the wallet completes the transaction into a valid, processable one.

Auto-Select Inputs, Change, and Fees: How the Wallet Builds a Complete Transaction for You article cover

Why Automatic Handling Is Needed

In BSV's UTXO model, spending isn't about deducting a number from a balance. Instead, you select several old outputs as inputs and create new outputs.

Suppose you want to create a 100 satoshi data output. Your wallet might not have a UTXO of exactly 100 satoshis. Instead, you have:

  • UTXO A: 300 satoshis
  • UTXO B: 500 satoshis
  • UTXO C: 1200 satoshis

The wallet must decide which UTXO(s) to use. After selection, it must pay a fee. If the total input value exceeds outputs plus fee, the excess must not disappear; typically, it goes back to a change output controlled by the wallet.

Simplified formula:

Code
1total inputs = total target outputs + change output + fee

Doing this manually, beginners often forget change, underestimate fees, select the wrong UTXOs, or construct inputs that cannot be validated.

Wallet Auto-Selects Inputs

When you call createAction() and provide only outputs, the wallet selects inputs from its UTXO set. This selection is not random. The wallet typically considers:

  • Whether available UTXOs are sufficient.
  • Whether UTXOs are locked or in use.
  • Transaction size and fees.
  • Whether to reserve certain UTXOs.
  • The wallet's own privacy and fund management strategies.

Applications see the result, but should not assume these details do not exist. Automatic input selection is a convenience, not magic.

Wallet Automatically Generates Change

If the wallet selects a 1000 satoshi UTXO, but your target output is only 100 satoshis, the remainder must be handled. A real transaction cannot simply write:

Code
1input: 1000 satoshis
2output: 100 satoshis

Otherwise, the difference becomes the fee. In most cases, the wallet creates a change output:

Code
1input: 1000 satoshis
2output 1: 100 satoshis (to the target purpose)
3output 2: remainder (back to wallet control)
4fee: to miners

The change output is still an on-chain output, spendable in the future. It may also reveal fund associations, so production wallets use strategies to minimize privacy issues.

Wallet Automatically Calculates Fees

Fees typically depend on transaction size, network policy, and miner rates. BSV's large block approach aims for low-cost massive transactions, but each transaction still must meet the fee requirements accepted by the processing network.

SDK and wallet help estimate fees, but applications should still know two things. First, fees are not fixed constants: more inputs, more outputs, and more complex scripts increase transaction size. Second, too low a fee may cause the transaction to be rejected or fail. Automatic estimation reduces error probability but does not guarantee success.

Corresponding Process in createAction

Beginner-level calls often provide only outputs:

TypeScript
1const response = await wallet.createAction({
2 description: 'My first BSV transaction',
3 outputs: [{
4 satoshis: 100,
5 lockingScript: dataScript,
6 outputDescription: 'My first data output'
7 }]
8})

You do not write inputs, change, or fees in the code, but the wallet handles them behind the scenes. Later, when you move to lower-level transaction construction, you will explicitly handle:

  • inputs: which previous UTXO to reference, what unlocking script to provide
  • outputs: to whom, locking script, amount
  • fee: total inputs minus total outputs

First understand the automatic flow (Phase 7), then manually dissect (Phase 8).

Position in the BSV Tech Stack

In BSV applications, the wallet layer manages funds. It is not a simple signing button but a UTXO manager, authorization gateway, and transaction construction assistant. This aligns with BSV's layered development:

  • Application layer: describes business actions
  • Wallet layer: manages UTXOs, authorization, signatures, change, fees
  • Network layer: accepts, validates, propagates, and mines transactions
  • Indexer layer: allows applications to query business data

As you progress, you will understand each layer's boundaries.

Risks of Automatic Handling

Automatic handling is convenient, but production applications cannot be completely unaware.

  • If the wallet selects many small UTXOs, transaction size may increase.
  • Poor change strategies may expose addresses or fund associations.
  • If the application repeatedly initiates similar actions, it may need idempotency and retry logic to avoid creating multiple transactions for the same business action.
  • If network services are temporarily unavailable, transactions may be delayed or fail.

Beginners can rely on automatic handling, but they should know that behind it lies a deterministic transaction structure.

Common Misconceptions for Beginners

  • Automatic input selection does not guarantee the optimal combination. Different wallets have different strategies.
  • Change is not "internal wallet accounting." Change outputs are real on-chain outputs.
  • Fees are not costs to arbitrarily save. Without sufficient fees, a transaction may not be processed.
  • A successful transaction creation does not mean the business action is complete. You still need to track status.
  • Using high-level interfaces does not mean understanding UTXOs is unnecessary. It's just a different learning order.

References

Collection

BSV Basics

Part 33 of 43

A curated series covering BSV, blockchain fundamentals, protocol capabilities, and ecosystem knowledge.

View collection

Reading path

Progress 33/43

  1. 01
    Part 1

    Why BSV Still Matters for Long-Term Settlement

    Read article

    A compact note on settlement design, data permanence, and why builders keep looking at BSV.

    Apr 30, 20265 min read
  2. 02
    Part 2

    P2P Electronic Cash: What Is Peer-to-Peer Electronic Cash?

    Read article

    Peer-to-peer electronic cash is the starting point for understanding Bitcoin and BSV. It emphasizes transferring digital value directly through transactions, signatures, and a public ledger, rather than relying on central platform accounts. This article explains peer-to-peer, cash, double spending, UTXOs, and why BSV emphasizes low fees, high-frequency transactions, and on-chain data.

    May 19, 202615 min read
  3. 03
    Part 3

    Timestamp Server: Why Is Blockchain a Time-Ordered Record?

    Read article

    Blockchain is not just a ledger; it is also a public time-ordering machine. This article explains what the timestamp server means in Bitcoin/BSV, the role of block height and confirmations, and the value of timestamps in double-spend prevention and data attestation.

    May 20, 202615 min read
  4. 04
    Part 4

    Proof of Work: Why Can Miners Order Transactions?

    Read article

    Proof of Work uses a mechanism that is expensive to compute and cheap to verify, allowing miners to compete for new blocks in an open network and using accumulated work to determine the ordering of transaction history. This article explains how PoW works, why miners can order transactions, its security significance, and the miner-economic logic behind BSV’s focus on large blocks, low fees, and high transaction volume.

    May 20, 20265 min read
  5. 05
    Part 5

    How the BSV Network Works: Transactions, Blocks, Fees, and Miner Incentives

    Read article

    This article explains the basic mechanics of the BSV network: how transactions are constructed, how blocks organize them, how miners are incentivized, and why BSV places special emphasis on low fees, large blocks, and high-throughput on-chain transactions.

    May 20, 202615 min read
  6. 06
    Part 6

    Introduction to SPV: Why Lightweight Clients Do Not Need to Download the Full Chain

    Read article

    SPV (Simplified Payment Verification) allows lightweight clients to verify that a transaction is included in a block without downloading the full blockchain. This article explains how SPV works, the role of Merkle proofs, what SPV can and cannot prove, and why SPV is a core capability in the BSV architecture.

    May 20, 202615 min read
  7. 07
    Part 7

    How BSV’s Roadmap Differs from BTC and BCH: Why It Emphasizes On-Chain Scaling, Low Fees, and Enterprise Data

    Read article

    BTC, BCH, and BSV all come from Bitcoin, but their technical roadmaps differ significantly. This article explains why BSV chooses a low-fee, high-volume, large-scale on-chain scaling approach, through the lenses of on-chain scaling, low fees, a stable protocol, SPV, enterprise data, and real-world challenges.

    May 20, 202615 min read
  8. 08
    Part 8

    WIFs, Mnemonic Phrases, and HD Wallets: An Introduction to Key Management in BSV Wallets

    Read article

    WIFs, mnemonic phrases, and HD wallets all relate to key storage, recovery, and derivation, but they mean different things. This article explains their differences, the role of xpubs, and security practices for BSV wallets and application development.

    May 20, 202625 min read
  9. 09
    Part 9

    What Is the Difference Between BSV Mainnet and Test Environments?

    Read article

    Mainnet carries real value, while test environments are for learning and development. This article explains the differences between BSV mainnet and test environments, common risks, SDK usage considerations, and practical environment-separation recommendations for project configuration.

    May 24, 20265 min read
  10. 10
    Part 10

    A Wallet Is Not an Account System: BSV Wallets Manage Keys and UTXOs

    Read article

    A BSV wallet is not a traditional account system. There is no single on-chain balance field; instead, the wallet calculates balances and creates transactions by managing private keys, UTXOs, inputs, outputs, signatures, and related data. This distinction is essential for understanding change, multiple inputs, non-custodial wallets, and application authorization.

    May 24, 202615 min read
  11. 11
    Part 11

    BRC-100: A Standard Interface Between Wallets and Applications

    Read article

    BRC-100 is an interface standard in the BSV ecosystem that describes how applications and wallets communicate. It emphasizes that applications express business intent while wallets retain control of keys, helping non-custodial applications request transaction creation, signing, and returned results in a safer and more consistent way.

    May 24, 20268 min read
  12. 12
    Part 12

    What Is a Transaction Input? Understanding BSV Transaction Inputs and UTXO References

    Read article

    A transaction input is the funding source of a BSV transaction. It references a specific unspent output from a previous transaction and provides unlocking data. Understanding inputs helps explain the UTXO model, outpoints, double-spend conflicts, fee calculation, and transaction debugging.

    May 26, 202615 min read
  13. 13
    Part 13

    Understanding BSV Transaction Outputs: Amounts, Locking Scripts, and UTXOs

    Read article

    A transaction output is a new unit of value created by a BSV transaction, usually consisting of an amount and a locking script. Outputs can represent payments and change, but they can also carry OP_RETURN data, token state, or business records. Understanding outputs, UTXOs, and output indexes is fundamental to understanding BSV transactions and application protocol design.

    May 26, 202615 min read
  14. 14
    Part 14

    What Is a TXID? Its Role, Common Misunderstandings, and Design Tips in BSV

    Read article

    A TXID is the most common transaction identifier in BSV. It can be used to look up transactions, reference outputs, store business records, and build SPV proof flows. But a TXID identifies the whole transaction, not a specific output, and it does not mean the transaction is final. Real applications should store it together with the output index, status, raw transaction, and proof materials.

    May 26, 202615 min read
  15. 15
    Part 15

    Understanding Change Outputs in BSV Transactions: Why They Must Be Explicitly Included

    Read article

    A change output is a key concept in BSV’s UTXO model: old UTXOs must be spent in full, and any unspent amount must be returned to the payer through a new output. This article explains how change works, how it relates to fees, change addresses, privacy, and practical UTXO management.

    May 26, 202615 min read
  16. 16
    Part 16

    How BSV Transaction Fees Are Calculated: Total Inputs Minus Total Outputs

    Read article

    BSV transaction fees are not stored as a separate field. They are calculated as total inputs minus total outputs. Understanding this rule helps developers handle change correctly, estimate fees, manage UTXOs, and avoid accidentally turning remaining balance into fees.

    May 26, 202615 min read
  17. 17
    Part 17

    What Is a Raw Transaction? The Basics of BSV Transaction Serialization, TXIDs, and Signatures

    Read article

    A raw transaction is the original byte representation of a transaction after protocol-compliant serialization, usually shown as a hexadecimal string. It is central to TXID calculation, signing, broadcasting, and debugging, and is a key concept for understanding how BSV transactions work at the protocol level.

    May 26, 202610 min read
  18. 18
    Part 18

    Endian Issues in BSV Transaction Debugging: Why TXIDs Can Look Reversed

    Read article

    Endian is a common byte-order issue when debugging BSV transactions, especially in raw transactions, TXIDs, outpoints, numeric fields, and Merkle proofs. Understanding the difference between display format and serialized bytes helps avoid false “TXID mismatch” or “proof calculation failed” conclusions.

    May 26, 202612 min read
  19. 19
    Part 19

    What Is a UTXO? Understanding the Foundation of the BSV Transaction Model

    Read article

    A UTXO, or “unspent transaction output,” is the basic unit of the BSV transaction model. A wallet balance is not an on-chain account field, but the sum of controllable UTXOs. Understanding UTXOs helps explain BSV inputs, outputs, change, fees, double-spending, Script, and parallel processing.

    May 27, 202615 min read
  20. 20
    Part 20

    In BSV, Spending Means Consuming Old UTXOs and Creating New Ones

    Read article

    In BSV, spending does not update a balance. It consumes old UTXOs and creates new ones. Understanding this model helps explain payments, change, transaction chains, and the basic logic behind tokens and application state transitions.

    May 27, 202612 min read
  21. 21
    Part 21

    One Address Can Have Many UTXOs: Understanding Addresses, Balances, and Transaction Construction in BSV

    Read article

    In BSV’s UTXO model, an address is not an account or a single balance slot. The same address can be associated with multiple UTXOs, and a wallet balance is simply the sum of those outputs. Understanding this is essential for transaction construction, fee handling, UTXO fragmentation, and privacy.

    May 27, 20265 min read
  22. 22
    Part 22

    Why the UTXO Model Is Suitable for Parallel Processing – The Technical Foundation of BSV Scaling

    Read article

    The UTXO model splits state into independent outputs, allowing transaction verification to proceed in parallel, providing a key data structure foundation for BSV's on-chain scaling and high throughput. This article compares the account model with the UTXO model, explains the principles of parallelism, practical limitations, and its relationship with Teranode and application design.

    Jun 2, 20264 min read
  23. 23
    Part 23

    Understanding Bitcoin Double Spend: Why the Same UTXO Cannot Be Spent Twice

    Read article

    Double spending is a core problem for digital cash systems. This article explains the principle, transaction structure, miner's role, 0-conf risk, signatures and double spend, and engineering best practices.

    Jun 2, 20264 min read
  24. 24
    Part 24

    Understanding Locking Script in BSV: The Core Mechanism of Spending Conditions

    Read article

    Locking script is an essential part of a BSV transaction, defining the conditions under which a UTXO can be spent. This article starts from the basics, gradually explaining the location of locking scripts, their relationship with addresses, how they are expressed, and their importance in applications.

    Jun 2, 20264 min read
  25. 25
    Part 25

    Deep Dive into Unlocking Script: The 'Key' to Spending Blockchain Transactions

    Read article

    Unlocking script is the unlocking material in a transaction input that satisfies the locking conditions of a previous output. This article comprehensively explains the concept, location, working principle, and common misconceptions.

    Jun 2, 20264 min read
  26. 26
    Part 26

    P2PKH: BSV's Most Common Payment Script Template Explained

    Read article

    P2PKH (Pay to Public Key Hash) is the most basic payment script in Bitcoin/BSV. This article breaks down its core logic, workflow, relationship with addresses, unlocking conditions, and why BSV developers need to understand it.

    Jun 2, 20264 min read
  27. 27
    Part 27

    OP_RETURN: A Beginner's Guide to Writing Data on the BSV Blockchain

    Read article

    Learn the basics of OP_RETURN, how it differs from regular payments, data format requirements, privacy considerations, and use cases.

    Jun 2, 20263 min read
  28. 28
    Part 28

    Understanding Bitcoin Script: A Stack-Based Scripting Language and Its Execution Model

    Read article

    Bitcoin Script is a stack-based scripting language used to verify transaction spending conditions. This article starts with the concept of a stack, illustrates its execution process with examples, and explores key points such as P2PKH, restricted design, and BSV applications, helping readers understand the core mechanism of this on-chain verification language.

    Jun 2, 20263 min read
  29. 29
    Part 29

    Standard Scripts vs Non-Standard Scripts: The Easily Overlooked Boundary in BSV Development

    Read article

    A transaction that is valid under consensus rules may not be processed by the network. Understand standard scripts and miner policies to avoid broadcast failures.

    Jun 2, 20264 min read
  30. 30
    Part 30

    Getting Started with @bsv/sdk: Installation, Verification, and First Steps

    Read article

    Introduces the installation, project setup, and verification process for @bsv/sdk, helping developers quickly enter the BSV development environment and understand the SDK's role in the tech stack.

    Jun 15, 20264 min read
  31. 31
    Part 31

    WalletClient: The Communication Entry Point Between Applications and Wallets

    Read article

    WalletClient is a standardized client for connecting wallets in BSV applications. It enables applications to describe transaction intent while the wallet handles authorization, signing, and UTXO management, thereby isolating complexities like private keys, UTXOs, and signing.

    Jun 15, 20264 min read
  32. 32
    Part 32

    Creating Your First BSV Transaction with createAction(): A Beginner's Guide

    Read article

    createAction() is the core method in the BSV SDK, allowing applications to describe transaction actions via a high-level interface while the wallet handles signing, fees, and broadcasting. This article explains its principles, parameters, and practical usage.

    Jun 15, 20264 min read
  33. 33
    Part 33Current

    Auto-Select Inputs, Change, and Fees: How the Wallet Builds a Complete Transaction for You

    Read article

    When using the high-level SDK, the wallet automatically selects spendable UTXOs, generates change outputs, and calculates fees. This article explains how this process works, its benefits, and potential risks.

    Jun 15, 20264 min read
  34. 34
    Part 34

    Writing Data to the BSV Blockchain: From OP_RETURN to Application Protocols

    Read article

    BSV transactions can do more than transfer satoshis. By including data outputs, you can record text, hashes, or business events on-chain. This article starts with the first Hello BSV transaction, explains the difference between data outputs and payment outputs, how to construct an OP_RETURN using the SDK, the reason for hex encoding, and how to move toward structured protocol design.

    Jun 16, 20264 min read
  35. 35
    Part 35

    Viewing BSV Transactions with WhatsOnChain: A Complete Guide from txid to On-Chain Structure

    Read article

    This article teaches you how to use the block explorer WhatsOnChain to view transaction details, understand core concepts like inputs, outputs, scripts, and fees, and leverage the explorer to infer the underlying logic of the SDK.

    Jun 16, 20264 min read
  36. 36
    Part 36

    Getting started with BSV transactions: the right way to manually specify inputs

    Read article

    In BSV's UTXO model, manually specifying transaction inputs is a must-have skill for advanced development. This article explains the essence of inputs, the required information, code examples, and common pitfalls, helping you avoid the mental trap of "debiting an address."

    Jun 18, 20264 min read
  37. 37
    Part 37

    Manually Specifying Transaction Outputs: A Key Step in Designing BSV Applications

    Read article

    Learn how Bitcoin transaction outputs work by constructing transactions manually. This article covers output types, change rules, index ordering, and common pitfalls, helping you advance from “sending transactions” to “designing BSV applications.”

    Jun 18, 20263 min read
  38. 38
    Part 38

    Bitcoin Transaction Fees: Calculation, Influencing Factors, and Practical Guidelines for BSV

    Read article

    Transaction fees are not an explicit field but the difference between total inputs and total outputs. Understanding the fee calculation logic, factors affecting transaction size, and BSV network policies is essential for building on-chain applications.

    Jun 18, 20264 min read
  39. 39
    Part 39

    Why Every Input in a Bitcoin Transaction Needs Its Own Signature

    Read article

    Understand the necessity of multi-input signatures in Bitcoin transactions, avoid common misunderstandings, and learn the basics of P2PKH signing, SDK usage, and what signatures actually protect.

    Jun 18, 20264 min read
  40. 40
    Part 40

    BSV Transaction Serialization: From Object to Broadcast

    Read article

    Understanding transaction serialization is key to connecting application development with the blockchain network. This article explains why serialization is needed, the standard transaction structure, the role of hex, serialization and deserialization in the SDK, the relationship with txid, and common misconceptions, helping you move from calling the SDK to debugging on-chain data.

    Jun 18, 20264 min read
  41. 41
    Part 41

    BSV Transaction Broadcasting: A Complete Guide from Construction to Submission

    Read article

    In BSV development, constructing a transaction is only the first step. This article explains the significance of transaction broadcasting, common misconceptions, pre-broadcast checks, how to interpret the return value, and failure reasons, helping developers correctly submit transactions to the network.

    Jun 18, 20264 min read
  42. 42
    Part 42

    Transaction Chains: How a Transaction Spends a Freshly Created UTXO

    Read article

    To truly grasp the Bitcoin white paper's definition of a coin as a chain of digital signatures, you must understand transaction chains. This article starts from the simplest model to explain how UTXOs transfer between transactions and why transaction chains are essential for state management in BSV applications.

    Jun 18, 20264 min read
  43. 43
    Part 43

    The Bitcoin Block Header: The 80‑Byte Foundation for SPV and Light Clients

    Read article

    The block header is an 80‑byte summary of a Bitcoin block. It does not contain full transactions, yet it is the critical structure linking the proof‑of‑work chain and committing to the transaction set. This article explains the header fields, Merkle root, and SPV principles, helping you understand how BSV enables massive scaling.

    Jun 20, 20265 min read

Recommended articles