2

I'm trying to figure out how transactions are actually handled by bitcoind.

I'm looking at the full list of RPC methods and there are missing documentation for some most interesting methods.

move

I know there are two methods of moving bitcoins between addresses either via direct p2p transaction or via the so-called off-chain transaction. If I believe correctly, the built-in wallet of bitcoind allows us to send off-chain transactions via the move method. Sadly, it's not very well documented, but I want to know exactly how it works.

Here's the documentation for it:

move <fromaccount> <toaccount> <amount> [minconf=1] [comment]

Move from one account in your wallet to another
  1. So, if account A has one BTC and account B has zero. What will happen if I first move one BTC from A to B using off-chain transaction and then issue a direct transaction of 1 BTC from B to C?

  2. Also, what minconf parameter is for? As far as I understand, off-chain transactions doesn't require confirmations.

sendfrom

Here's the documentation for the sendfrom method:

sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]

<amount> is a real and is rounded to 8 decimal places. Will send the given amount to the given address, ensuring the account has a valid balance using [minconf] confirmations. Returns the transaction ID if successful (not in JSON object).

It requires an account to send bitcoins from.

  1. What if I have multiple addresses/transactions for the specified account? What strategy bitcoind uses to determine from which addresses to make a transaction and how much bitcoins to use from each?

  2. What minconf parameter is for?

sendtoaddress

sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to]

<amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful.
  1. The account is not specified for this call. What account bitcoind will use? The default one?

  2. Why there is no minconf parameter for this one?

1
  • 1
    Many pages in the wiki are outdated, you might want to also check out the Bitcoin Developer Reference. This wiki page is deprecated, but explains Bitcoin Core's accounts functionality. As Shabahat M. Ayubi explained below, the accounts feature in Bitcoin Core is deprecated.
    – Murch
    Commented Dec 23, 2016 at 9:36

2 Answers 2

3

First of all, there are many types of off-chain transactions. Any movement of value in BTC that does not directly correspond to a blockchain transaction can be classified as one. This includes:

  1. giving someone a computer/phone that has a wallet witg BTC on it
  2. giving someone a private key/physical bitcoin.
  3. giving someone access to a shared webwallet account
  4. sending money from one account to another within the same service (which simply decrements one person's balance and increments another's balance)
  5. payment channels, including Lightning, which negotiate a small number of transactions that correspond to the net effect of many more value transfers.

The move command in bitcoind does not result in an off-chain transaction; it simply increments one internal counter and decrements another. It is off-chain for sure, but it's hard to call it a transaction. All you've done is changed how you're counting the money you already have control over.

A service (like #4 above) could potentially use bitcoind's move command to implement a (simple) off-chain transaction system. But it at least requires having a setup where multiple people have accounts on your system, and them treating you as a custodial for their money.

As for the questions you're asking:

  1. Accounts are a completely independent concept from addresses. From bitcoind's perspective, there is no such thing as an address balance. There is the wallet balance (how many coins the wallet has control over in total), and account balances (which are simply internal bean counters, with no relation to anything on the blockchain). When a new transaction sends M money to address A, and address A is associated with account C, the wallet balance goes up M, and the account balance for C goes up. When you send money with sendfrom, the named account is debited. But the actual on-chain transaction created always uses any coins the wallet has control over. Again: there is no relation between on-chain coins (transaction outputs) and account balances.

  2. The move command used to do a balance check on the to-be-debited account, and fail if it did not have enough counting only transactions with at least minconf confirmations. This functionality was removed a long time ago, and the minconf parameter is ignored now.

  3. Bitcoind treats the whole wallet as owning the coins, and it will use any coins available for any transaction it creates. There is no relation between coins and accounts. sendfrom simply allows you to specify which account balance to decrease.

  4. sendfrom does a balance check on the debited account, and will fail if it would make the account balance negative, counting only crediting transactions with at least minconf confirmations. This feature is not very reliable, as fees can make the account go negative despite the balance check before.

  5. sendtoaddress always debits the "" account, and does not do a balance check on it, so the "" account balance can go negative (as long as the wallet balance - the sum of the account balances - is positive). Again: it does in no way restrict which coins are used to construct the transaction.

  6. Because sendtoaddress does not do a balance check, there is no way in which a minconf parameter would have an effect. Normally, all coins with 1 confirmation (if they come from other wallets) or 0 confirmation (if they come from yourself) are spendable, though for example the spendzeroconfchange setting modifies this).

As already pointed out, the account balance system and the move command are deprecated because they are very hard to understand and use correctly. If you need accounting, implement it yourself on top.

1
  • Thank you Pieter for an elaborate answer. This really cleared things for me now. Also, we've decided to implement our own accounting system and to treat Bitcoin wallet as a single shared account for all customers, as you suggested in the last sentence. Commented Dec 23, 2016 at 16:46
1

An off-chain transaction means in simple terms that the parties involved in the transaction basically exchange their private keys. Say you want to pay your friend 1 BTC. You would just give the private key to your address holding the 1BTC. Go through this link for more details. Now coming to your questions.

  1. Firstly, note that accounts and the move api have been deprecated an no longer used. Just for explanation sake, accounts are nothing but a set of addresses in your bitcoind wallet. Now the move command actually transfers the BTC from the addresses in one account to the other. There is no way you can convince the bitcoind client to share the private key and not move the funds(because it already has all the private keys). So the scenario you have given doesn't make sense.

  2. The minconf is for the client to know to use only those transaction outputs which have as many mnimum confirmations as you have provided.

  3. sendfrom is also deprecated since accounts are deprecated. What the bitcoind wallet does is that it combines the funds in all your addresses to send the money to the address specified (if the value you wish to send is not available in a single address)

  4. same as point 2

  5. As I said accounts are deprecated, so it will use the address which has more than the value specified and if not, combine addresses to send the money to the recipient address.

  6. same as point 2

Edit: Point 1: The move command simply decrements one accounts virtual internal virtual balance, and increments another and does not move the BTC's. As corrected by Peter Wuille

3
  • Thank you for your answer. It clears this for me a bit. Also, how do I know what features or API calls are deprecated or not? It looks like documentation is poor and severely outdated. Commented Dec 22, 2016 at 5:50
  • Through the terminal try typing the api without the parameters it requires, for example, just type move and read the output, you would see there it is written that it is deprecated, but can still be used. Commented Dec 22, 2016 at 6:08
  • 2
    The move command does not move funds from one address to another. It simply decrements one internal virtual balance, and increments another. Accounts are not addresses. They are indeed scheduled to be removed in a future version (partially because they're very hard to understand). Commented Dec 23, 2016 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.