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.