blockchain – Best way to add META info to UTXOs?

I want to create a database of META tags associated with BTC UTXOs and ETH accounts. Eventually I would like to do the same for all major blockchains and their (multiple in some cases) assets. Ideally I’d want to store all this info on a single distributed database, most likely a new blockchain. I understand that this will be a huge amount of info though but provided the fact that these MEYA tags will be opt-in only this might not be as dramatic as it sounds. What is the most efficient way to go about with this project?

bitcoind – Is there a script for bitcoin core which prints all spendable UTXOs given a private seed?

You can import a descriptor composed of the xpriv(s) (or xpub(s) if you just want to watch the coins) to the bitcoind wallet, and then rescan the block chain for transactions involving derived key up to a configured gap limit.

For importing the descriptor, use the importmulti RPC call in versions <0.21 and the importdescriptors RPC as of 0.21 (upcoming).

Both calls allow you to pass a creation timestamp in order to rescan the block chain from this point. You can otherwise manually call rescanblockchain.
Note that, depending on the number of blocks you are scanning, it will take some time. You can monitor the progress in your debug.log.

change – How is the UTXOs of each partially-spent TxIn determined?

  1. a transaction (Tx) can have multiple inputs (which are previous unspent transactions = UTXOs), let’s call them the TxIn

More accurate would be to say “unspent outputs from previous transactions”.

  1. a Tx can have multiple outputs (which thus become UTXOs before they will themselves become spent by being used as TxIn), let’s call them
    the TxOut
  2. the TxOut have a specific order N in the transaction: TxOut(0), TxOut(1), etc.
  3. each TxIn references the number N which corresponds to the index of the TxOut referred to in point 3 above, so this makes the link between
    a specific TxIn and a specific TxOut

Correct, we call the compound of transaction id and output index txid:vout the “outpoint” of a UTXO. As you describe, each input spends exactly one specific UTXO.

  1. each TxOut specifies a specific bitcoin amount (which represents the UTXO amount that can be later spent)
  2. each TxOut references one or multiple (in the case of MultiSig) bitcoin addresses (public keys) that can spend the amount

It’s a bit easier if you think of each output as being locked to a set of conditions that need to be fulfilled for spending. In single-sig the spending condition is “pay-to-(witness-)public-key-hash”. This lock is satisfied by a signature of the private key corresponding to the specified address. (The address in turn is derived from the hash of a public key which forms an asymmetric key pair with said private key.) In multisig the spending condition is “pay-to-(witness-)script-hash”. The funds are locked to the fullfilment of a specific script. The address in this case is derived from the hash of the script. Spending such a UTXO requires 1) revealing the script that hashed to the address, 2) fulfilling the conditions specified in the script. In the case where that script is a multisig construction, it would specify a set of public keys some subset of which is sufficient to unlock the funds. However, these scripts can take various other forms as well. I’d nit that “each TxOut references one or multiple bitcoin addresses that can spend the amount” is both an overgeneralization (because not all scripts must be multisig) and an inaccuracy (because the funds are locked to the script, not to multiple addresses).

  1. however, and this is what I don’t understand, the TxIn does NOT specify the amount of bitcoins that are used

If the TxIn does not specify the amount that is used, how do we
determine the spent amount for each TxIn, and thus the UTXO of the
part of the TxIn that remains unspent?

There is no way to partially spend a UTXO. Spending UTXO is binary, either they are unspent or they are spent. Since UTXO can only be spent in full, any remainder from a payment gets collected into one or multiple outputs in which the sender pays themselves (see e.g. How does change work in a bitcoin transaction?).

Example, a transaction with 2 inputs and one output (assuming no
fees):

  • TxIn(0) whose UTXO before spending is 1 BTC
  • TxIn(1) whose UTXO before spending is 1 BTC
  • TxOut(0) whose value is 1.5 BTC

How do we know which TxIn, and how much of which, was spent?

  • was it TxIn(0) for 0.75 and TxIn(1) for 0.75?
  • was it TxIn(0) for 0.5 and TxIn(1) for 1?

What am I missing? Because given the above, it is not possible to
determine the spent proportion of each input.

The answer is that both TxIn(0) and TxIn(1) get spent completely and the transaction is created with two outputs: TxOut(0): 1.5 BTC to recipient and TxOut(1): 0.5 BTC to sender.

script – Could it be possible to secure transactions against double-spending with other utxos?

I’m new to Bitcoin Script, and I was wondering if it is possible to use funds from one utxo to “insure” that other utxo will not be double-spent (until the Lightning Network will save us all).
Suppose I have 0.1 bitcoin in a utxo with pubkey pubKey1, and 10 bitcoins that I would send to an output script that would do something like:

  1. If nLocktime is greater than X, verify that the stack contains a signature that matches some pubKeyHash2.

  2. Otherwise, verify that the stack contains: <sig1> <payload1> <sig2> <payload2>, such that <payload1> != <payload2>, and <sig1> matches pubKey1 + <payload1>, and <sig2> matches pubKey1 + <payload2>.

i.e. until nLocktime passes, anyone who can find 2 different signatures of pubKey1 (of two different payloads) can win the 10 btc prize.

This will create a huge incentive for me to never sign two transactions (or any two payloads) with the private key of pubKey1. I could obviously take the risk, double-spend the 0.1 btc by publishing two transactions, and immediately try to claim the 10 btc prize myself, but once I published the two double-spending transactions, the miners would try to take all the 10 btc to themselves (and probably ignore any transaction that tries to take even a small portion of the prize without offering them 100% fee).

I don’t see how the current op-codes allow this kind of script – I couldn’t even find an “OP_CHECKLOCKTIME” (found only “OP_CHECKLOCKTIMEVERIFY”), and “OP_CHECKSIG” operates on data from the transaction and not on arbitrary payloads in the stack.

What do you think? Could this be implemented in the future? Could this be implemented in other cryptocurrencies? This could be useful when you don’t want to wait for even a single block confirmation, for example in ATMs.

How are UTXOs managed in Ledger Live?

Take this Bitcoin transaction:

In my Ledger Live, I can see that 0.3881168 BTC has left the wallet:

Ledger Live screenshot

Which is strange, because I actually only sent 0.3878 BTC to 16fPHhrdaBuRNPH1YbEqC4fDE8tCUXNmuM, the rest 0.00065121 BTC being one of my newly created UTXOs whose value was credited to my wallet.

Why does Ledger Live not display the amount actually spent but rather the gross amount which is the sum of all the UTXO used? How can I see only the amount spent?

bitcoin core – Bitcoinjs-lib how to add multiple utxos in addInput

Hi i want to do bitcoin bech32 address transactions using bitcoinjs-lib, here is my code below, it works fine when my address has only one utxos but when it grows to two or more like its array which does not pass in the addInput method, so it fails. Please help me browse it or what is the solution for handling multiple input utxos.
Thank you

const bitcoin = require("bitcoinjs-lib");

//creating and signing a native p2wpkh
//p2wpk: addInput('00000....', 0, prevOutScript)
//sign(0, keyPair,,,value)

let NETWORK = bitcoin.networks.litecoin; 
let txb = new bitcoin.TransactionBuilder(NETWORK);

//get unspent output details
let txid = "9d1517a2499ce5496ba3c826785b25982c63dc5b59b0c256303bf19128e44747"; //transaction id of the output you want to spend
let outn = 0;  // n out

let keypair = bitcoin.ECPair.fromWIF(WIF, NETWORK);
let scriptPubkey = bitcoin.script.witnessPubKeyHash.output.encode(
                       bitcoin.crypto.hash160(  
                           keypair.getPublicKeyBuffer()
                       )
                   );

//add input
txb.addInput(txid, outn, null, scriptPubkey);

//add output
txb.addOutput("ltc1q9umns6nuxv3xrhzdwlmhkzujewu6hulyuwgx30",4999000); //first argument is receiving address, the second is the amount we are sending after deducting a mining fee

//signing
txb.sign(0, keypair, null, null, 5000000); //NOTE the amount is the FULL amount of the unspent output, NOT the amount we are sending
let tx = txb.build();
let txhex = tx.toHex();

console.log(txhex);

balance – How to query all utxos for an address from a full node?

I'm new to blockchain and I'm trying to create my own block explorer from scratch to really learn more about Bitcoin. I am currently running a full node in a Raspberry Pi, and I have already decoded the chainstate / UTXO package with a levelDB library for Node.js. The content of this database is not exactly what I found in the documentation, but it led me well enough to completely decode this database.

Basically, the keys are the transaction identifiers with the index of the output, and the values ​​contain the height, whether or not it is a coinbase transaction, the amount and the Address (before base58 encoding) of each utxo.

However, I'm not sure how to query this database effectively to get all utxos for a specific address without scanning the entire chain state. It took me about 10 minutes to get all the utxos from one address, which is totally unacceptable.

I guess my specific question is how do I query this database via values ​​instead of keys? Or if there is a better way to do it, maybe via the blockchain itself? maybe an RPC bitcoin-cli call?

transactions – How are UTXOs sent to other addresses?

this is a fairly general conceptual question. I think I don't fully understand the dynamics of blockchain transactions yet.

Let's say we have A, B and C exchanges on the Blockchain:

  • A previously transferred 10BTC to B. So B has an unspent transaction exit
    (which it can spend) referenced by the address of A.
  • Now, B wants to pay 5BTC to C and does so by using the UTXO he has from A's previous transaction and routing it to C.
  • Thus, B transmits the UTXO with the address from A to C and also gives the change 5BTC to itself.

So now doesn't the list of transactions look like this?

contributions:

The exits:

  • address_C 5BTC
  • address_B 5BTC

Now, to me, it sounds ok from B's point of view, but it seems that A transferred money to C and B, instead of B transferring money to C. I guess my understanding is wrong then, because it cannot work like that. So where is my mistake?

From C's point of view, shouldn't it look like this:

contributions:

The exits:

  • address_C 5BTC
  • address_B 5BTC

Otherwise, C would also have the unspent outflow from A again, and this outflow from A would somehow be transmitted over and over again.

Don't judge me for my misunderstanding please: D, if there are good reads you can recommend, that would be great.

Thank you!

Better,
JC

How does the bitcoin application in production drop UTXOs?

AFIK, UTXO of an address can not be recovered with the help of bitcoin-core, without importing the address in the wallet.

  1. How can an application in production get UTXO?
  2. Do all applications use an indexed database like Insight or Abe to get UTXO?
  3. Is there a way to get UTXO from bitcoin core without importing the address into the wallet?

wallet – Errors with `walletcreatefundedpsbt` and unresolved UTXOs

I try to use walletcreatefundedpsbt with a watch portfolio only.

With 2.0 BTC in the portfolio reserved for watches, I try to create a psbt that sends 0.2 BTC without specifying the entries and receive an error "Insufficient funds":

$ bitcoin-cli -regtest -rpcwallet=watchonly getbalance "*" 0 true
2.00000000

$ bitcoin-cli -regtest -rpcwallet=watchonly walletcreatefundedpsbt '()' '({"bcrt1qnv3tl3z9cll9faqf79ppfn3rrp7pn9wwmq04p5gqgqtxg55xfxuslkyk94": "0.20000000"})' 0 '{"includeWatching": true, "changeAddress": "bcrt1qa4h6amsgyc878k094grqh6ktmgvp97dt6et9cy5hjmyxlgd9q63q3p6hch"}' true
error code: -4
error message:
Insufficient funds

When I specify entries for the same RPC call, I get an error (confusing) "The signing transaction failed":

$ bitcoin-cli -regtest -rpcwallet=watchonly walletcreatefundedpsbt '({"txid": "1d76879500aecafde541770b5d44ccec5955b4c1a455fae446bf1df7b5ea43e9", "vout": 0}, {"txid": "e5a8dfa9459ac154fe62652e1d43049dae13f11815da36cc32881e27917a0dff", "vout": 1})' '({"bcrt1qnv3tl3z9cll9faqf79ppfn3rrp7pn9wwmq04p5gqgqtxg55xfxuslkyk94": "0.20000000"})' 0 '{"includeWatching": true, "changeAddress": "bcrt1qa4h6amsgyc878k094grqh6ktmgvp97dt6et9cy5hjmyxlgd9q63q3p6hch"}' true
error code: -4
error message:
Signing transaction failed

These entries are visible in listunspentbut they are not "solvable".

$ bitcoin-cli -regtest -rpcwallet=watchonly listunspent
(
  {
    "txid": "1d76879500aecafde541770b5d44ccec5955b4c1a455fae446bf1df7b5ea43e9",
    "vout": 0,
    "address": "bcrt1qupu3f9ekx2jpu9adgnrckkuh60d0x5zunmrxla34cwc5z79lajrs52gcpu",
    "label": "",
    "scriptPubKey": "0020e07914973632a41e17ad44c78b5b97d3daf3505c9ec66ff635c3b14178bfec87",
    "amount": 1.00000000,
    "confirmations": 205,
    "spendable": false,
    "solvable": false,
    "safe": true
  },
  {
    "txid": "e5a8dfa9459ac154fe62652e1d43049dae13f11815da36cc32881e27917a0dff",
    "vout": 1,
    "address": "bcrt1qz9xlsapracexvk7gwjd8ytf9c5ckyeg6v64lmuun8j9x6l2770cs42f7kl",
    "label": "",
    "scriptPubKey": "0020114df87423ee32665bc8749a722d25c53162651a66abfdf3933c8a6d7d5ef3f1",
    "amount": 1.00000000,
    "confirmations": 103,
    "spendable": false,
    "solvable": false,
    "safe": true
  }
)

These UTXO correspond to exotic scripts that can not be expressed in the descriptor language and were imported with the importmulti PRC. During the import, the following warning was displayed:

$ bitcoin-cli -regtest -rpcwallet=watchonly importmulti '({"scriptPubKey": "0020e07914973632a41e17ad44c78b5b97d3daf3505c9ec66ff635c3b14178bfec87", "witnessscript": "63522102a7451395735369f2ecdfc829c0f774e88ef1303dfe5b2f04dbaab30a535dfdd62102303cc8dc4e50bb574899b4715c0ddcd63268137b2d95011ff0e71db0968d819d2103d9dcfae4253ef1dd7b2401f82f79b1e739e76ad22ad30cd6a58a04076a033e5a53ae6702f401b1755221033defb46605b0bf90e99821150926daabc0a909ae4d7e09ddd9cc691735896709210245449f5d5cb7cd0d299fcbfd7a3bf2e46a5ae43bdc75289f5ab1e0c7654cc057210299f94c03fc71ae8ced4d3a4f739cc2f227687885b8d1a5184ad1de14faa6c71c53ae68", "internal": false, "keypool": false, "timestamp": "now", "watchonly": true})'
(
  {
    "success": true,
    "warnings": (
      "All private keys are provided, outputs will be considered spendable. If this is intentional, do not specify the watchonly flag.",
      "Importing as non-solvable: unrecognized script. If this is intentional, don't provide any keys, pubkeys, witnessscript, or redeemscript."
    )
  }
)

Are these two errors caused by the same problem – the absence of "solvable" utxos?