-1

Regards to all,

I am completely new to blockchain and bitcoin as its most popular implementation.

I have some probably basic questions for someone, but it's really important for me to get it right. It is about accounts, addresses and wallets. I will number them and give some comment as I understood it. If I have not understood something well, I would ask you to indicate it.

  1. What is an address?

The address is created from the public key via hash functions. It is used to indicate to whom bitcoin is sent and from whom it is received.

  1. What is an account?

An account represents some kind of abstract concept that is associated with an address. Blockchain does not know the concept of an account. Actually the account can be represented as the knowledge of the private-public key pair on which the address was created.

  1. What is a wallet?

Blockchain, similar to an address, is wallet-aware. It's just some kind of client application that will store the private-public key pairs (thus it will have the addresses associated with that account), calculate the balance, facilitate user interaction with the blockchain, etc.

  1. Is each wallet connected to only one address or account?

No, the wallet has as many addresses and accounts as you want. In other words, you can hold as many public-private key pairs as you like, and therefore addresses and accounts.

The last question is about the balance of the wallet. I know balance is calculated based on UTXO. So, my question is, is this balance calculated by addresses, that is, by accounts? In other words, if you have 5 private-public key pairs, there will be 5 addresses (accounts) where for each they will look which UTXOs belong to it and then calculate 5 balances (one for each address/account). So, one wallet with 5 accounts and a separate balance for each of them. Is the above written correct, or is the balance calculated by finding the UTXO associated with the wallet addresses and then the balance is calculated as the total value. In other words, no matter how many addresses there are, there will always be only one balance, that is, there will always be only one account per wallet. If the second is true, it actually means that the concept of an account does not even exist within Bitcoin, that is, that a wallet is actually an account. I ask because in Metamask wallets, as I have seen, you have multiple accounts (one account corresponds to one address) in one wallet and a balance in each account. It's separate.

Thank you very much for your help.

5
  • Hi Filip, our website works best if a topic is started by asking an open question, and answers are posted in response. It tends to not work well, if you post many questions or incorporate your own answer into your question post. Perhaps you could please rephrase your question post into a question and respond to it with the answer you're giving.
    – Murch
    Mar 12 at 4:12
  • 1
    1. What is an address Mar 12 at 10:48
  • 1
    2. What is an account? -- In Bitcoin Core Mar 12 at 10:50
  • 1
    3. What is a wallet Mar 12 at 10:52
  • Please check out our tour for an overview of how our site works.
    – Murch
    Mar 12 at 12:51

3 Answers 3

2

is this balance calculated by addresses, that is, by accounts?

You are wrong to conflate addresses and accounts. There are no accounts in the Bitcoin network, nor in the current version of the Bitcoin core wallet, nor in the blockchain data.

There are no balances anywhere in the Bitcoin network data. None in the blockchain.

Most wallets choose to show you a total amount of money in UTXOs for which the wallet holds a private key. Most call this a balance because people are familiar with balances of bank accounts but Bitcoin doesn't work like a bank accounts - it is cash. Balances don't really apply to cash.

Bitcoin core used to have an "account" feature but that was an arbitrary label you could apply to addresses to help you organise your money. That feature was removed and replaced by "labels"

Any "balance" shown by a wallet is likely to be a total across all addresses UTXOs spendable by use of the private keys generated by the wallet - and therefore a total across at least all "addresses" that might be specifiable for locking scripts relating to many or all of those UTXOs.

Custodial accounts exist, they are provided by businesses who want to earn an income from cash that people would otherwise keep in their own personal wallets. The balance shown in these accounts is rather like an IOU. There's no guarantee of any sort that the business actually holds any cash or that it can pay you what it owes you.

Bitcoin's inventor primarily wanted to create a system by which one party could pay a second party without any need for a trusted third party to act as intermediary. The idea of custodial accounts is clearly in direct conflict with that goal.

Accounts almost invariably mean custodial accounts. An exploitation by businesses of what was intended to be purely a peer to peer cash payment system. The sort of business exploitation that leads to MtGox, Quadriga-CX, FTX and huge loss of money for thousands of people.


In short, The data circulated in the Bitcoin network and the data in the blockchain

  • have no accounts
  • have no addresses
  • have no balances

Ye Olde Blockchain:

enter image description here

In this cash daybook (cash journal), each page is a block, each line is a UTXO, a primitive proto-Bitcoin. It's just that the network protocol involved moving lumps of metal and paper between people's pockets rather than electrical impulses between people's computers.

11
  • First of all, thank you very much for your reply. Second, I also realized that the concept of account, wallet and its balance does not exist in the context of blockchain, so I labeled them as something abstract, something that exists in user applications only to facilitate interaction for users. At the end, you wrote that the network has no accounts, balances and addresses? I understand the first two, but how do you think there is no address? I mean, even in text you wrote the following: Any "balance" shown by a wallet is likely to be a total across all addresses.
    – dassd
    Mar 12 at 14:51
  • 1
    A Bitcoin "address" is a string of printable characters that a Bitcoin recipient (e.g. a seller of goods or services) shows to a Bitcoin sender (purchaser of goods or services), often in the form of a 2-D barcode, so that the sender can create a specific locking script in one output of a transaction. It is only the locking script that exists in the Bitcoin data in the network or in the blockchain. Wallets may show you addresses corresponding to a standard type of locking scripts for which the wallet contains private keys that can be used to create a corresponding unlocking script. .... Mar 12 at 18:29
  • 1
    ... Some types of locking scripts don't have have any standard address. Despite this, I sometimes write about Bitcoin addresses because this is a lot to describe every time we want to discuss Bitcoin payments. Sometimes you can lose sight of the forest because the trees get in the way. Mar 12 at 18:29
  • P.S. Your (implicit?) criticism is valid, It is just that sometimes I don't have the time to work out a completely unambiguous yet concise answer. Mar 12 at 18:32
  • So there are no addresses in the bitcoin blockchain? I mean even @Murch (comment below) talks about addresses. Also, I am reading Mastering Bitcoin by Andreas M. Antonopoulos and addresses are also discussed. Or maybe you want to say that there are addresses that are used to create a lock script that is then used in transactions, and bitcoin only recognize that (bitcoin does not recognize the addresses)? Now you have me completely confused. Do you have a suggestion for a good book or material that goes into ultra detail about the structure and workings of the Bitcoin blockchain?
    – dassd
    Mar 12 at 19:01
2

All spendable bitcoins are locked in UTXOs (Unspent Transaction Outputs)

When you want to spend bitcoin, you use one or more of your UTXOs as inputs to a transaction, and create one or more outputs. Since these inputs are now spent, they are no longer UTXOs, and while the new outputs are not spent, they are UTXOs.

So when you spend bitcoin you spend UTXOs and generate new UTXOs.

UTXOs are locked by locking scripts, and there are different locking scripts:

  • P2PK (Pay to Public Key) where the UTXO is locked to a particular public key, and you need to present a signature (by the corresponding private key) to unlock it;

  • P2PKH (Pay to Public Key Hash) where the UTXO is locked to a public key hash, and you need to present the public key and a signature to unlock it;

  • P2SH (Pay to Script Hash) where the UTXO is locked to a particular script hash, and you need to present the original script and a way to unlock this script to unlock the output;

  • Others, but I will stop right here for simplicity.

When you want to send me some bitcoins, what will happen is you are going to spend one or more of your UTXOs and lock those bitcoins in one UTXO I control. So, I need to tell you how I want my UTXO locked.

And here is where addresses come through: it’s a way for my wallet to inform your wallet how I want my UTXO locked.

So, if I show you an address starting with ‘1’, I’m saying that I want my UTXO locked in a P2PKH script with the following public key hash (that your wallet finds in the rest of the address).

If I show you an address starting with ‘3’, I’m saying that I want my UTXO locked in a P2SH script with the following script hash (that your wallet finds in the rest of the address).

Addresses also have a checksum suffix to prevent errors.

There is no address format for P2PK.

A wallet is a tool where you store secrets (private keys, master seeds, …) and sign transactions. Remember, you need to present signatures to unlock your UTXOs, and this is where those signatures come from.

For privacy reasons you should never reuse a public key.

A modern wallet is Hierarchical Deterministic, which means it doesn’t need to store all private keys it has ever used/generated. It just needs to store a master seed, since all keys can be derived in a deterministic way from that master seed.

To calculate the balance for a specific master seed, the wallet goes like this:

  1. Derive the first private key (and corresponding public key)
  2. Calculate possible locking scripts for that public key (P2PK, P2PKH, …)
  3. Search the UTXOs set for UTXOs locked with any of the above scripts
  4. When finds one UTXO locked that way, add the value of that UTXO to the balance
  5. Repeat process until it finds 1000 straight public keys with no UTXOs
2
  • Good answer! Perhaps “tool” would be better than “place” as a label for what the wallet is. The gap limit used by Bitcoin Core is 1000, not 20.
    – Murch
    Mar 15 at 13:12
  • @murch thanks for the suggestion and correction. Changed.
    – bordalix
    Mar 15 at 16:59
1

Is each wallet connected to only one address or account?

Addresses have the character of invoice identifiers. You should only use each address once in the context of a specific payment interaction. Addresses are used by recipients to inform senders what output script they expect the payment to be locked to. I am not sure how the concept of accounts as you describe it is useful in this context.

You mention Metamask—Ethereum works very differently in regard to tracking funds: it’s an account-based system. Funds are associated with one reused address and you can freely spend any portion of your balance. Bitcoin uses the UTXO-model: your funds are structured in discrete chunks that have to be spent in full like coins and bills in the physical world. Sure, you can sum up all the coins and bills in your wallet and refer to that sum as a balance. You can’t spend your whole Bitcoin wallet balance though, because you’ll also need to pay transaction fees, you can only spend discrete chunks of it and will need to consider change outputs, etc. so that may be confusing.

In Bitcoin, the most recent use of “account” that I’ve seen was people using the term as an opposite to “wallet”: if you manage your own key material and self-custody your funds, you have a wallet, when you use a custodial service that only shows you your balance they owe you, you have an account.

3
  • So, if I understood correctly. A wallet contains private-public key pairs and thus addresses derived from a given public key. A new address (that is, a new private-public key pair) should be used for each transaction, but it doesn't have to be. UTXO is tied to addresses, where will a wallet containing given addresses, then add up all UTXO across all addresses and display that to the user as a balance?
    – dassd
    Mar 12 at 15:03
  • Wallets only “contain” private keys. They may track transactions and UTXOs that are relevant to the wallet owner, but those are not “in the wallet” but part of the global state of the network. Addresses don’t exist in transactions, they exist only out of band. Addresses are just a transfer format for the recipient to inform the sender what output script to use to pay them: they’re a user-friendly shorthand for some output scripts.—If you wanted to get an idea of your spendable funds, yes, you should sum up all of your UTXO’s value. You might call that the balance of a wallet.
    – Murch
    Mar 12 at 20:54
  • Thanks for the help, I appreciate it.
    – dassd
    Mar 13 at 17:45

Your Answer

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

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