Bitcoin Q&A: Public Keys vs. Addresses

Bitcoin Q&A: Public Keys vs. Addresses

Public Keys, Addresses, and Transactions

In this section, Andreas Antonopoulos explains the difference between public keys and addresses. He also discusses how wallets generate new addresses for each transaction and how change is handled in transactions.

Public Keys and Addresses

  • Addresses are produced by hashing the public key twice.
  • Private keys produce public keys. Public keys produce addresses.
  • You cannot calculate the public key from the address, but you can calculate the address from the public key.

Wallet Address Generation

  • Wallets that generate new addresses for each transaction have a seed that is used to generate all of the addresses your wallet will use.
  • Old addresses are not forgotten when generating new ones; they are still tracked on the blockchain to see if they receive money.
  • When spending money, wallets may spend from multiple different addresses with different private keys.

Change in Transactions

  • Wallets find all of the fractions of bitcoin (i.e., unspent outputs) held by an address and use them as inputs to a transaction.
  • Each input must be signed with its corresponding private key.
  • If an output has more bitcoin than needed for a payment, change is required because inputs spend previously unspent outputs (UTXOs).
  • Change can be returned back to yourself or given as a fee to miners.

Transaction Fees

  • Transactions with multiple inputs and one output pay a fee even if just reorganizing funds.

Transactions and Vanity Addresses

In this section, Andreas explains how transactions work on the blockchain and how fees are involved. He also discusses vanity addresses and how they can be generated using the VanityGen command.

Transactions on the Blockchain

  • Transactions on the blockchain look like any other transaction.
  • They have to be done on the blockchain because everybody needs to see it.
  • This means using up some resources on the network and paying a transaction fee.

Aggregating or Cleaning Up Unspent "Dust" Outputs

  • When fees go down, aggregating or cleaning up unspent "dust" outputs often happens.
  • This is when outputs are too small to be spent individually for a reasonable fee.

Vanity Addresses

  • A vanity address is an address with a sequence of characters in it that spell something interesting.
  • The VanityGen command allows you to generate these special addresses.
  • To generate a vanity address, you keep trying until you find one that starts with your desired sequence of characters.

SIGHASH_ALL Flag

In this section, Andreas explains what the SIGHASH_ALL flag is and how it works in signing inputs and outputs in transactions.

Signing Inputs with Different Private Keys

  • Each input will be signed by the private key that corresponds to that address.
  • The SIGHASH_ALL flag tells the system that the hash being calculated is a hash of all inputs and outputs.

Hashing Algorithm

  • The hash is signed by the private key that corresponds to that input, and the signature is stored in that input.
  • Each input has its own signature; each signature in each input is made by the private key corresponding to that input's address.
Video description

What is the difference between public keys and addresses? How are new addresses generated? How are change addresses generated? Why have two outputs? Do you still pay fees if you are sending bitcoin to new addresses in your own wallet? What is the VanityGen command? What does the SIG_HASH flag do? More from 'Mastering Bitcoin': https://github.com/bitcoinbook/bitcoinbook/blob/f8b883dcd4e3d1b9adf40fed59b7e898fbd9241f/ch04.asciidoc Chapters 0:00 What is the difference between public keys and addresses? 0:57 If my wallet automatically generates a new address for each transaction, will bitcoin previously sent to me on a different address be transferred to the new address just generated? If someone is going to send me funds to a previously-used address, will I still receive them? 3:54 How can we generate a new address to receive change? 4:17 Why not have a single output with the exact amount of BTC, instead of two outputs, one of which is change? 5:17 Do transactions with multiple inputs and one output pay a fee, even if the wallet is just reorganizing funds? 7:00 Can you explain the VanityGen command? What is a vanity address? 10:55 SIGHASH_ALL is for signing all inputs and outputs. How can all inputs be signed with one signature, when each of the inputs have a different private key? These questions are from the MOOC 9.3 and 9.5 sessions which took place on March 2nd and March 16th, 2018 respectively. Andreas is a teaching fellow with the University of Nicosia. The first course in their Master of Science in Digital Currency degree, DFIN-511: Introduction to Digital Currencies, is offered for free as an open enrollment MOOC course to anyone interested in learning about the fundamental principles. If you want early-access to talks and a chance to participate in the monthly live Q&As with Andreas, become a patron: https://www.patreon.com/aantonop RELATED: Advanced Bitcoin Scripting Part 1: Transactions and Multi-sig - https://youtu.be/8FeAXjkmDcQ Advanced Bitcoin Scripting Part 2: SegWit, Consensus, and Trustware - https://youtu.be/pQbeBduVQ4I Reusing addresses - https://youtu.be/4A3urPFkx8g Airdrop coins and privacy implications - https://youtu.be/JHRnqJJ0rhc Wealth distribution statistics - https://youtu.be/X2Qsz4eaSPY Mixing services - https://youtu.be/rKoMvOH4zoY How do mnemonic seeds work? - https://youtu.be/wWCIQFNf_8g Using paper wallets - https://youtu.be/cKehFazo8Pw What is Segregated Witness? - https://youtu.be/dtOjjB4mD8k Spam transactions and Child Pays For Parent (CPFP) - https://youtu.be/t3c0E4fkSNs Andreas M. Antonopoulos is a technologist and serial entrepreneur who has become one of the most well-known and respected figures in bitcoin. Follow on Twitter: @aantonop https://twitter.com/aantonop Website: https://antonopoulos.com/ He is the author of two books: “Mastering Bitcoin,” published by O’Reilly Media and considered the best technical guide to bitcoin; “The Internet of Money,” a book about why bitcoin matters. THE INTERNET OF MONEY, v1: https://www.amazon.co.uk/Internet-Money-collection-Andreas-Antonopoulos/dp/1537000454/ref=asap_bc?ie=UTF8 [NEW] THE INTERNET OF MONEY, v2: https://www.amazon.com/Internet-Money-Andreas-M-Antonopoulos/dp/194791006X/ref=asap_bc?ie=UTF8 MASTERING BITCOIN: https://www.amazon.co.uk/Mastering-Bitcoin-Unlocking-Digital-Cryptocurrencies/dp/1449374042 [NEW] MASTERING BITCOIN, 2nd Edition: https://www.amazon.com/Mastering-Bitcoin-Programming-Open-Blockchain/dp/1491954388 Subscribe to the channel to learn more about Bitcoin & open blockchains! Music: "Unbounded" by Orfan (https://www.facebook.com/Orfan/) Outro Graphics: Phneep (http://www.phneep.com/) Outro Art: Rock Barcellos (http://www.rockincomics.com.br/) Join the aantonop Channel: https://aantonop.io/joinaantonopyt