<p>I asked yesterday if it's possible to have a tx from A to B then B to C in the same block, with the second tx spending the UTXO of the first one (with initial balance of B is 0)</p>
<p>Apparently it is : <a href="https://bitcoin.stackexchange.com/questions/101206/can-two-related-spends-be-in-the-same-block">Can two related &quot;spends&quot; be in the same block?</a></p>
<p>But now i'm trying to test this with bitcoinlib in Python.
My code is :</p>
<pre><code>wallet = Wallet.create('MyWallet',
                        keys = seed_phrase,
                        witness_type = &quot;segwit&quot;)

address = wallet.get_key(0).address
address2 = wallet.get_key(1).address
address3 = wallet.get_key(2).address

wallet.transactions_update()

fee = 1_000
send_value = wallet.balance() - fee

tx = wallet.send( [(address2, send_value)],
                    fee = fee,
                    offline = True)

wallet.transaction_import(tx)

send_value2 = send_value - fee

tx2 = wallet.send( [(address3, send_value2)], 
                     account_id = 1,
                     fee = fee,
                     offline = True)
</code></pre>
<p>The first tx work correctly because the first address have a balance, but then the second one fail with :</p>
<pre><code>WalletError: Create transaction: No unspent transaction outputs found or no key available for UTXO's
</code></pre>
<p>I think the problem is with the importation of the first tx in the wallet</p>
<p>Any idea on how to fix this ?
Thank you</p>

CC BY-SA 4.0
2023-12-11T16:37:11.753Z
I have a couple ideas someone may want to investigate if they’re writing an answer: (1) It looks like the `account_id` parameter allows you to manage multiple accounts within one wallet. You only specify `account_id` on the second transaction, but not on the first. What happens if you drop the `account_id` parameter? (2) The library may not support spending unconfirmed funds.
Murch
CC BY-SA 4.0
2023-12-11T21:37:30.550Z
(1) account_id is zero by default, if i remove it for the second tx then it send from address 0 to address 2, not what i want (2) yeah probably, if i wait for the first tx to be confirmed in the blockchain then it works, but it takes too long to wait for new blocks
sgbbfbf
CC BY-SA 4.0
2023-12-11T22:03:21.083Z
Have you considered testing on testnet, regtest, or signet?
Murch
CC BY-SA 4.0
2023-12-11T22:19:56.057Z
no i tested this on mainnet directly, i think the library will do the same with testnet
sgbbfbf
<transactions><utxo><python-bitcoinlib>
Chain 2 transactions in same block with bitcoinlib in Python
sgbbfbf
# Chain 2 transactions in same block with bitcoinlib in Python

(Asked by: username_0 on 2023-12-09)

I asked yesterday if it's possible to have a tx from A to B then B to C in the same block, with the second tx spending the UTXO of the first one (with initial balance of B is 0)
Apparently it is : Can two related "spends" be in the same block?
But now i'm trying to test this with bitcoinlib in Python.
My code is :
wallet = Wallet.create('MyWallet',
                        keys = seed_phrase,
                        witness_type = "segwit")

address = wallet.get_key(0).address
address2 = wallet.get_key(1).address
address3 = wallet.get_key(2).address

wallet.transactions_update()

fee = 1_000
send_value = wallet.balance() - fee

tx = wallet.send( [(address2, send_value)],
                    fee = fee,
                    offline = True)

wallet.transaction_import(tx)

send_value2 = send_value - fee

tx2 = wallet.send( [(address3, send_value2)], 
                     account_id = 1,
                     fee = fee,
                     offline = True)

The first tx work correctly because the first address have a balance, but then the second one fail with :
WalletError: Create transaction: No unspent transaction outputs found or no key available for UTXO's

I think the problem is with the importation of the first tx in the wallet
Any idea on how to fix this ?
Thank you

**Tags:** transactions, utxo, python-bitcoinlib

> **Comments:**
> **username_1**: I have a couple ideas someone may want to investigate if they’re writing an answer: (1) It looks like the `account_id` parameter allows you to manage multiple accounts within one wallet. You only specify `account_id` on the second transaction, but not on the first. What happens if you drop the `account_id` parameter? (2) The library may not support spending unconfirmed funds.  
> **username_0**: (1) account_id is zero by default, if i remove it for the second tx then it send from address 0 to address 2, not what i want (2) yeah probably, if i wait for the first tx to be confirmed in the blockchain then it works, but it takes too long to wait for new blocks  
> **username_1**: Have you considered testing on testnet, regtest, or signet?  
> **username_0**: no i tested this on mainnet directly, i think the library will do the same with testnet  

---

## 0 answers

