Building Blockchain from scratch with Go

Tram Ho

Introduce

In the previous section we learned about Transaction, build a simple CLI to handle transactions. If you haven’t seen it, please review the previous parts before starting to understand the story. I hope everyone understands the first part. In this part we continue the story to understand more about blockchain, there will be no code in this part 4.

Github: https://github.com/lequocbinh04/the-simple-blockchain

Continue the story

Wednesday, March 27

Jack invested so much (2000$) that he forgot his rent, and now Jack doesn’t have a dime left. Jack called Jay – his innkeeper.

  • Jack: Hello, I’m sorry but I don’t have enough money to pay the rent right now…
  • Jay: What’s wrong?
  • Jack: The Blockchain Bar opened an ICO with a great offer so I accidentally invested all my money in it, I bought 2000 Tokens for only $1000
  • Jay: What are you talking about? What is ICO? What are tokens? Can you pay my rent in another way?
  • Jack: So let me transfer you 1000 TBB which is equivalent to 1000$, you can use it to pay for drinks at the bar. Let me call John to transfer the tokens.
  • Jay: Ok sir.

John confirmed the transaction, and he decided there would be a hidden fee of this transaction (50TBB), he didn’t want that but the shareholders (who invested early in TBB) wanted a profit from TBB. John thinks to himself, after all, only he has access to the DB, so Jack probably won’t notice this small fee.

Whatever comes will come

Thursday, March 28

Jack enters the bar and celebrates his birthday.

  • Jack: Hey John! Today is my birthday, give me the most expensive drink here.
  • John: Happy birthday!!! Here is your country: Crystal Head Vodka , but its price is 950TBB but your balance is only 949TBB
  • Jack: Huh?? I remember I have 999 TBB left?
  • John: Well, your TBB transfer with Jay last week cost 50TBB as a transaction fee.
  • Jack: Not acceptable? What kind of business are you doing, I would never accept a transaction if I knew the fees were so high, I trust your system, and you do that?
  • John: I’m sorry, actually you are my loyal customer, I didn’t want to do that but the shareholders forced me. Okay, I will reprogram the system so that it is decentralized , people can make their own transactions without going through me , that will increase the reliability of the system.
  • Ordering a drink now takes seconds instead of minutes
  • Customers who forget their wallets at home can borrow tokens from each other
  • I wouldn’t worry about losing customer data (again) since everyone owns a copy of it .
  • Every time a transaction, if everyone agrees, is added to the db , it will not be changed .
  • If early investors (shareholders) want to introduce a new fee, or increase an existing fee, everyone will be notified of it.
  • Jack: Well that sounds good sir, but is it possible?
  • John: Yes! just a little bit: hashing, linked lists, immutable data structure, distributed replication, and asymmetric cryptography!
  • Jack: Wowwwwwwwwwwwwwwwwwwwwww! I don’t understand anything but just do it John.

Another day has passed, and John will get 100 TBB as a reward for upgrading & maintaining his DB:

summary

[🔑] ​​Blockchain developers aim to develop protocols so that their users can transact, exchange tokens with each other in a transparent, verifiable manner. The parameters of the blockchain must be clearly defined from the outset.

The blockchain is a database. The total token supply, user initial balance, and blockchain settings will be located in the Genesis file. The balance, the initial state of the blockchain recorded in the genesis file is never changed.

Changes to the database are called transactions (Transaction | TX). Transactions are events for actions in the system.

Share the news now

Source : Viblo