A basic blockchain for educational purposes.
- Create a genesis block with one transaction where:
- Alice receives 50 coins and Bob receives 25 coins
- Mine that block
- Add it to the blockchain
- Create a new block with two transactions where:
- Charlie receives 5 coins
- Alice sends 30 coins to herself and sends 20 coins to Bob
- Mine that block
- Add it to the blockchain
- hex, for encoding/decoding data into/from hexadecimal representation
- crypto-hash, for cryptographic hash functions
cargo run
- Concatenate together all the bytes composing the block's fields (aside from the hash field)
- Generate unique data fingerprint: the hash
Difficulty is expressed in this way:
- The first n bytes of the hash that must be zero
- The number of bits or bytes as the beginning of the hash that must be zero
- Generate new nonce (an arbitrary number that can be used just once)
- Hash bytes (computationally heavy step)
- Check hash against difficulty
- Insufficient? Go back to step 1
- Sufficient? Continue to step 4
- Add block to the blockchain