Skip to content

Change handling is too simplistic #800

Description

@arjaz

Describe the feature you'd like

Change handling is too simplistic. It's not possible to specify the position of the change output. That is critical for some smart contracts to work correctly, because the outputs positions are visible on-chain and controlled by the transaction builder.

It would be really useful to mark an output as a change output. This way a user can provide the minimum amounts the output is expected to have, and the library can calculate the change and put it in the marked output. Change outputs can easily be some script outputs with datums and complicated requirements for their positions.

Is your feature request related to a problem? Please describe.

Yes, change output is always added last and can't be controlled by users.

Describe the solution you'd like

Add an option to mark an output as "change" where the change would be added during building.

Additional context

No response

Would you be willing to implement it?

  • Yes, I will implement it.

Activity

  1. twwu123 commented on Mar 16, 2026

    @twwu123
    Collaborator

    This issue is actually somewhat more complex than simply flagging an output as change. It's possible to add such a feature, but if the change output is too large to be a single utxo, then it needs to be split. It's difficult to know where to put the second, third, fourth, etc. change outputs. If I put it at the end, we have the same problem. Flagging multiple outputs as change also makes it difficult. Currently the workaround would be to build a perfectly balanced transaction and so the transaction builder doesn't create a change output. But this might be hard with the automatic fee calculations also. You could alternatively set a slightly generous fee and then build a perfectly balanced transaction with your exact intended outputs.

  2. twwu123 commented on Mar 16, 2026

    @twwu123
    Collaborator

    Because of the issue I mentioned above, it's usually unwise to have scripts be so restrictive about change outputs, the change outputs can be so large, it needs to be split into multiple utxos, they can be extremely messy with an insane number of tokens, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions