Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: nerses on October 21, 2024, 09:28:25 AM



Title: How to add a custom struct to PSBT and handle transaction fees using BIP-174
Post by: nerses on October 21, 2024, 09:28:25 AM
I am working on a Bitcoin transaction where two parties are involved. The goal is to lock funds and create a custom struct in the transaction output. Here's how I intend to set it up:

First party provides the funds and initiates a Partially Signed Bitcoin Transaction (PSBT) using BIP-174. Second party will add a custom struct (possibly metadata or a specific output detail) to the PSBT without providing any funds. I'm wondering if the following is possible:

Can the second party add a custom struct (output or metadata) to the PSBT, while the first party is the only one providing funds? Who will be responsible for paying the transaction fees? Will the first party bear all the fees since they are providing the input funds, or is there a way to distribute this between the parties? Are there any known constraints or best practices for achieving this within Bitcoin's protocol and the PSBT standard? I would appreciate any guidance on whether this setup is feasible and how to handle fees and struct addition in a PSBT.


Title: Re: How to add a custom struct to PSBT and handle transaction fees using BIP-174
Post by: nextidearly on October 21, 2024, 04:37:27 PM
The second parity can be structured with a custom struct (output or metadata). As long as the first party is only the one providing funds, that will pay all the fees. Bitcoin blockchain don't support splitting fees. But splitting fees are the most important in your case, we can adjust it manually by controlling inputs and outputs of the transaction. I think you can practice with bitcoinjs-lib which is the library for Bitcoin PSBT, addresses, etc.


Title: Re: How to add a custom struct to PSBT and handle transaction fees using BIP-174
Post by: ABCbits on October 22, 2024, 10:43:24 AM
I'm not expert on PSBT, but
1. BIP 370 (PSBT v2) improve BIP 174 (PSBT v0) which add more feature, mainly adding more input and output.
2. TX fee actually determined by subtract total coin on the input and total coin on the output. That means determining who's responsibility to pay TX fee entirely depends on all inputs and outputs.



Secondly  in the usual cases the party providing the fund usually bear the transaction fee but you can also distribute the fees between the two party by using
output tagging (BIP-68) or you can negotiate the fee distribution outside the protocol

BIP 68 isn't about output tagging. It's about timelock which determine when an UTXO can be spend, not about managing TX fee. Here's simple explanation about BIP 68 to other reader.



Title: Re: How to add a custom struct to PSBT and handle transaction fees using BIP-174
Post by: nerses on October 24, 2024, 02:34:31 PM
I'm not expert on PSBT, but
1. BIP 370 (PSBT v2) improve BIP 174 (PSBT v0) which add more feature, mainly adding more input and output.
2. TX fee actually determined by subtract total coin on the input and total coin on the output. That means determining who's responsibility to pay TX fee entirely depends on all inputs and outputs.



Secondly  in the usual cases the party providing the fund usually bear the transaction fee but you can also distribute the fees between the two party by using
output tagging (BIP-68) or you can negotiate the fee distribution outside the protocol

BIP 68 isn't about output tagging. It's about timelock which determine when an UTXO can be spend, not about managing TX fee. Here's simple explanation about BIP 68 to other reader.


Thanks for explanation. By the way in what platform I can see your illustrations on Bitcoin topics ? I have found only X but it doesn't seems the best platform to investigate something


Title: Re: How to add a custom struct to PSBT and handle transaction fees using BIP-174
Post by: ABCbits on October 25, 2024, 12:19:08 PM
--snip--
Thanks for explanation. By the way in what platform I can see your illustrations on Bitcoin topics ? I have found only X but it doesn't seems the best platform to investigate something

As i said previously, i never create any Bitcoin illustrations. But if you want to see more illustration created by @cygan, you can check https://twitter.com/BTCillustrated (https://twitter.com/BTCillustrated).


Title: Re: How to add a custom struct to PSBT and handle transaction fees using BIP-174
Post by: stanleyrivera219 on April 08, 2025, 12:45:10 PM
Yes, the second party can add a custom struct (like metadata or specific output details) to the PSBT, even if they are not providing any funds. The first party, who is funding the transaction, will typically bear the transaction fees, as they control the input funds. However, there are ways to structure the transaction so that both parties share the fees. One approach is to allocate a portion of the funds for fees in the outputs or adjust the input amounts to account for the fees. The PSBT standard allows for flexibility in this regard, but it’s important to ensure that the transaction’s total size and inputs/outputs are correctly balanced. Best practices include clearly defining fee allocation in the agreement and verifying the final PSBT before signing.