This is a pratical example showing how blockchain works using NodeJs.
You need to have Docker and DockerCompose in your machine.
docker network create blockchain_nodejs_network
docker-compose up --build
To sign the transactions
in the Blockchain you first need to generate a key pair:
node keygen.js
A ditributed database
which stores immutable transactions
(cannot be changed) records where the participans of the network (miners
) can validate and process the transactions.
The descentralized
consensus along with transaction signatures and the fact that the blocks integrity is validated in cascaded using cryptography makes the technology very safe.
It is a record
in your Blockchain that is only valid if followed by a previous valid block in the chain. The Block contains the data you want to save, i.e. amount, time, sender, receiver, etc.
In order to transfer or receive money in a Blockchain network, you need to have a wallet
or an address
. This is basically your account. If you want to mine
or receive
money, you give the another user your public key
. If you want to give money for another address
, then you need to sign the transaction
with your private key
.
You can check the TRON accounts as example to see wallets/addresses.
The Prof-of-work is what avoids the Blockchain to be spammed
and make difficult
for an attacker to change a block's hash and so for the consecutive blocks hashes (what would make a valid chain). For this, the Blockchain has the Mining
mechanism.
When you use the computational power to generate block hashes
accordingly certain difficulty
level and increment the block's nonce
, which will part of the block hash.
Blockchains like Bitcoin
are peer-to-peer networks, so mining coins to the Blockchain has a cost that is paid through Mining Reward
, which means receive coins
as reward for mining.
They are like contracts in the real world, but digital
, immutable
and stored in a blockchain.
Basically, they are computer programs
that hold the money
from wallets and transfer to another's when the contract rules are checked. In case of contract fails, it returns the money to original wallets.
The main characteristics of smart contracts are:
- They define rules.
- They check these rules.
- And they are self-executables.
You can check the TRON contracts as example.
Property of a Block that MUST change while mining
. The nonce
changes, so the Block Hash can change and we can mine it.