Introduction to Blockchain|Smart Contract and uses|ERC20 token|Applications

Blockchain it’s characteristics and components

  1. It is a list of blocks that stores the information of a particular node/person/system.
  2. There is an underlying distributed ledger system where each node has all the transaction history taking place in that blockchain network.
  3. A block has following properties like index — stores the index value of block, data — message present in block(transactions), Current Hash value, Previous block hash value, difficulty — level of mining difficulty, nonce — random value generated to modify the hash value, timestamp.Generally, the first block of a network is known as Genesis block.
  4. Cryptographic functions are the mathematical functions like sha256, keccak256 that are used to encrypt our data into fixed length size to protect our privacy and secure the transaction. These hash functions only create hash values. Digital Signatures are also used which uses encryption methods using public-private pair key to authenticate the user and verify the originality of message.
  5. When a transaction is executed it needs to be checked and verified by the other nodes or miners to add that block into blockchain network. This is done with the help of Proof of Work concept, where the network participants partcipate in finding the data hash value(generated taking into consideration of all properties of block) by changing the Nonce value such that final hash value must generate the target number of leading zeroes(can be called as difficulty). If a node is successful in finding data hash value he/she may get rewards in terms of bitcoins/any other digital currency. This process is known as Mining.
  6. Finally, after consensus of all the network peers for the newly generated block, it is finally added to blockchain network.
Nodes in a blockchain network
Demo image fig(0)

Etherium:

Smart Contracts:

  1. It is written in Solidity language similar to javascript which is a OOP’s language.
  2. Below is the Smart contract for sending ethers to the different address in fig 1.
Smart Contract. Fig(1)
Token Contract. fig 2

Why ERC20 token:

Functions of ERC20:

ERC20 interface. fig 3
  1. totalSupply() function give us the total supply or the sum of balances in a token contract as shown in fig 1.
  2. balanceOf() function takes address of owner as input, and balance of users as output
  3. allowance() function takes contract owner address and spender address , calculates remaining token that can be spent by the given address which returns it as output.
  4. transfer() function simply sends the token to address from the total supply.
  5. approve() function is to approve someone to spend tokens form our acccount where senders address and number of tokens to be spent is taken as input.
  6. transferfrom() function transfers tokens from one address to another address.
  7. Transfer() and Approval() are two events that are triggered according to the above functions. The former tells about the movement of tokens along different addresses while the latter gets the details about approval of tokens.
ERC20 optional elements. fig 4

Lets get down to code execution of ERC20 token:

ERC20. fig 5
  1. In the constructor we initialized a token with the following values.
  2. balanceof() function gives balance amount of input address.
  3. transfer() function transfers amount from senders address to receivers with the following required statements given in the first two lines of code in the transfer function
Fig 6

Applications:

  1. Maintaining Health Records : The records of an individual are secured and maintained at one place only, that is in block. For example, suppose I have medical records in three different countries, now doctors in each of these countries have no access to their other medical records. But using smart contracts, we have full control on our data as all our data is stored at one place only, and we can show only the necessary data to the hospital organizations instead of whole medical history which is secure in a manner.
  2. Smart Contract also help in clinical trials where lots of data of an individual are collected and are automatically submitted for an individual’s advantage.
  3. Several blockchain companies creates marketplace for users to monetize their own data preventing them from digital marketing frauds. To do so, Basic Attention Token is used which is an ERC20 token that serves as a utility between adverstisers, publishers and users. For example Brave browser.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

DRUG MANUFACTURING: BLOCKCHAIN IN PHARMACEUTICAL INDUSTRY

Blockchain in Banking BIP 360

Title:End-to-end encrypted survey

VISION OF THINKIUM

What Is EOS blockchain?

The New Age of AceD-Enhanced SC Auto farming, and deflationary.

Introduction to LavaSintex: IDO Platform on Avalanche

Defina Joins BSC MVB III Program!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
mudassir ali

mudassir ali

More from Medium

Get Started — Z3NS

Adding Tokens to MetaMask Wallet

Tresor Integrates Chainlink VRF to Help Conduct Provably Random Giveaways

How to Protect your Metamask Wallet