Saturday, 31 August 2019

How to implement Blockchain Technology & Smart Contract in an Organization?

     Smart Contracts facilitates the exchanges of value on the internet without the need of middleman or escrow service. Actually, Blockchain itself acts as a witness of contract. For ex, When two parties involved in the contract and agreed to draw a smart contract, the information in the contract turns into a block in the blockchain network which is visible to all nodes on the network. But, the identity and private information are anonymous. When one party sells and the other party wants to buy it, both parties draw a smart contract with sign and date. Now, One party puts all the information to transfer the ownership of the product and the other party deposit the money. When the date of the contract arrives, the ownership of the product will be transferred and money is automatically paid to another party. This smart contract paves the way to Ethereum. 
       Smart Contracts are programs which run on the blockchain. The contract is a set of rules that parties agree to govern the relationship between them. So, you have to define rules in programming. Smart contracts are coded in the blockchain. Solidity is a Turing-complete programming language which means you can code any logic into that language. Bitcoin script is missing one important component, that is loops(eg., for, while etc.,). Basically, loops tell the programs or certain piece of code in many iterations until the certain conditions are met. Smart contracts run on every single node in the chain. Each node has a history of all smart contracts, transactions and the current state of the smart contract. For ex, the provenance whitepaper discusses the blockchains to add transparency in supply chains. It talks about how the certificates are issued. All these certificates are sits in the blockchain. To facilitate the supply chain, they would use smart contracts. For ex.,when the product is sourced(eg, US, China) puts into the checkbox. Smart Contracts have the logic coded into it and the certificates are issued. You can see all the information about the product that you purchased and what was happening along the way. Then, you will be satisfied or dissatisfied of your product.     

Blockchain for Developers: Blockchain has some powerful qualities that enables the settlement of state transitions and forms the foundations for Decentralized Finance. It is important to understand the key technical details of how blockchain applied to different solutions. The issue is that we don't know the status of the node's distributed out on our network. Then, How can we protect our network when we have the nodes and don't know what's really happening with them?  The Byzantine Fault Tolerance algorithm identify and enforce good network players on our network. Also, there is proof of work which is used by the Bitcoin network and proof of stake algorithms. Proof of stake is like a voting system. These systems have different entities called validators. Any participant might be a validator and might post some of the stakes in that network coin as a bond in escrow on a network. Different nodes communicate in the method called Consensuses and Consensus algorithms update the true states.  Consensus means how to come to a new true state of affairs in our network and update on nodes. Blockchain is state change machine. It maintains the state of ledger balances until something happens and that true state needs to be updated to the new true state. It is the way for the system to reach consensuses about the transactions. Consensus Mechanism is a set of rules to check the validity of the transactions. It represents a way to elect the leader who proposes the transaction to process and for all participants to agree on the final state. For ex, When I bought a cup of coffee and my wallet balance is lower and the vendor is higher. That is the new true state of network and this information propagated and updated by all nodes.
    Blockchain has two accounts like Externally Owned Account and Contract Account and it has an own address attached to each account. Contract account accessible through invoking transitions stated in the contract code. It includes permission-based transitions and this act as a medium to call another contract transitions. It works like the contract owner to invoke the transition. Then, the code is processed and verified state transitions from the initial state to a final state.

BlockChain and Web 3.0:   In Web2.0, the front-end requesting the information from the central server. In Web 3.0 onwards, Blockchain plays a huge role. The back-end changes from the centralised web to decentralized web. For ex, When we interact with each other through facebook, it allows us interacting without the middleman. Still, the Facebook has a centralised server to control the data and privacy. If they want to charge for our ad, they can do so. In Web3.0, multiple blockchains run the application and copy of the blockchain will be stored in every single computer. The smart contracts govern how these applications will work. The code behind that social media will be stored in the blockchain and the blockchain will be running. The main advantage is that it control over the private key on the blockchain. Only, You have the control over data rather than a centralized server.

 Decentralized Applications(DApp): It is an interface for people to connect with applications. It contains an interface for people to interact with something on the blockchain. DApp consists of front-end and back-end which is a smart contract. When you participate in the network, actually, you get an Ethereum Virtual Machine(EVM). EVM is running on your computer and it encapsulates the transfer. Anything happens on the virtual machine stays on the machine. If something goes wrong, it will never spread on the rest of the hard drive and will never have access to private files that are safer from viruses.
        Any computation that runs on the blockchain, the developers of the smart contract needs to pay. So, you need to use the gas for any calculation that needs to run. It is like to pay for fuel for the car need to run. EthGasStation provides estimates on how much gas to pay and so on. In Ethereum,  ether is the currency to pay for the code. So, if you are a developer, you need to check out the gas estimates for your code.

Concept of Decentralized Autonomous Organizations(DAO): DAO is a business or organization whose decisions are made electronically by written computer code or through the vote of its members. It is a system of hard-coded rules that defines which actions an organization will take. Blockchain technologies introduced the concept of secure digital ledger, which could track the interaction of all the members across the internet and provide a safe and secure environment to build a decentralized autonomous organization. Blockchain technology uses the technique called trusted timestamping to combat against counterfeit transactions. Theoretically, the DAO company could run completely autonomous if the platform provided sufficient rules and flexibility.
      DAO was created Vitalik Buterin at 2016 on ethereum. It creates a venture capital fund which will help the development of decentralized applications to run on ethereum blockchain. The purpose of DAO is to provide an autonomous vehicle for fund management without traditional fund managers.With the emergence of Ethereum network, DAO moved up the technology stack from blockchain protocol to the smart contract.  DAO organization is stateless that means, it does not belongs to any country. DAO was crowdfunded through a token sale. If the organization is designed on the blockchain, it is a decentralized organization. Decentralized Organization means the server does not belong to one specific company. Because the contracts are written on the blockchain, it doesn't need human intervention. All the works happen on its own on the blockchain. This is the concept of DAO. For ex, the organization provides the computational service from the cloud to its customers. It is like a proprietary machine predicts certain things about marketing going to succeed or fail. With the power of blockchain, we can make them decentralized. It means the logic doesn't have to live on the silos of the organization. But, it lives on the blockchain. Therefore, if the organization is profitable and growing, then they can keep running even the people don't interested in it. So, it can survive on its own. Keep running and keep serving to the community is the notion of blockchain.
InitialCoinOffering(ICO):  ICO happens on the token layer of the Ehtereum, Neo or Waves protocol layer. If somebody creates a new idea of how to use the blockchain in an industry, then they use the ICO to fund this idea in a token layer. At the same time, ICO happens on the protocol layer that they can create and issue the coin in ICO.  In an ICO, they put the products and services in a closed environment and create the coins in the 3rd layer. Now, you can use the tokens to buy the products and get services so on. The public already knows that the company is successful and the ideas are great. Then, the people invest money in ICO as soon as coins are initially offered. The founders of the company keep control of all the tokens and profits. ICO is another way to raise money in order to fund its operations. There is no mining of tokens. Because minings are associated with coins in the 2nd layer.  Any startup's blockchain startup whitepaper contains information about how the project will work and mention the need for tokens. Also, why they need blockchain and the purpose of tokens.


Thursday, 15 August 2019

How to do a Blockchain Cryptocurrency Transactions effectively?

          In the crypto world, there are 3 important layers are implemented. The Layer-1 is the Technology or Blockchain. Layer-2 includes Protocol and Coin. Protocol is a set of rules that guides participants over the network to communicate with each other and dictates how to come to a consensus. It also dictates the public key and signatures to be used for authentication. Protocols are required for the whole network to function correctly. For ex, TCP, IP, HTTP etc., HTTP allows the browsers to display the website correctly. IP allows all the participant in the network. In the protocol layer, we have the Bitcoin, Ethereum, Ripple, Neo etc., This protocol relies on the Blockchain technology. Each Protocol has its own coins attached to it. Bitcoin is not just a currency. It is a protocol. It is used to reward people for mining, adding blocks in the blockchain, to purchase things from each other and so on.  Layer-3 is the Token. ICO is actually about tokens rather than coins. Token relies on smart contracts which are built on top of a different protocol. Bitcoin & Ripple does not have tokens which do not facilitate the smart contract. Ethereum is popular for creating smart contracts. There are hundreds of tokens in Ethereum. Waves and Neo have the tokens. In CoinMarketcap, you can see the market capitalization of each cryptocurrency, the tokens and its platform. If somebody investing in coins, they are investing in the protocol of the underlying coins. This is our road map of everything that fits in.

BitCoin EcoSystem: A  whitepaper of peer-peer electronic cash system submitted in 2008 that helps you to understand all the things. It includes the following participants.
       * There are Nodes. It is the term for devices the people use which they are mining the network and transacting with each other.
       * The miners are the people helps the blockchain to grow by mining and adding the transactions into blocks.
      *  Mining Pools are work together for mining process.

Understand the Mining Difficulty:  If you are a miner, mining the bitcoin, you should know how to  impose the current target and mining difficulty. In our previous example, we agreed to express target with leading Zeros. By setting the target of 4 leading zeros, we are reducing the pool size to quarter. If you
request one leading zero, you can effectively reduce the pool size by 16 times.  For ex,
Current Target = 18 leading zeros in 64 hexadecimal digit
Total possible 64 Hexa Decimal numbers = 16 * 16 ....16 = 1664    1077
Total Valid Hashes (with 18 leading zeros)  = 16* 16 ....16 = 1664-18   2 * 1055

So, the probability that your randomly picked hash is valid by: 2 * 1055 / 1077   = 2 * 10-22

            The mining difficulty can be calculated as Current Target / Max Target. Max target is set in, you can see the hash that has the current target of 18 or 19 leading zeros and the Mining difficulty. The difficulty gets adjusted every 2 weeks, so it shows the steps. Due to the decentralized system, the difficulty gets adjusted by nodes themselves. If you install the bitcoin software, the difficulty adjusted on its own because the algorithm coded in the bitcoin protocol. It may necessary that trillion times to find the golden Nonce to solve the cryptographic puzzle place at the inception of Bitcoin. The difficulty is adjusted at every 2016 blocks(or)2 weeks and the block should be released every 10 minutes.

Mining Process: The transactions to the miners come from mempool which is attached to every
node and every miner. Basically, these are unconfirmed transactions gets stored here before it gets included in the block. Blocks are added every 10 minutes. But, the transactions happen all the time. MemoryPool is the staging area for transactions. Fees in the Mempool are arbitrary that ranges from 0 to high fees. If the miner successfully created the block, he will get the fees. Normally, the miner will pick the transactions from higher fees. Now, the challenge to the miner is to find the golden nonce. The nonce will be in the range from 0 to 4 billion. They have the timestamp to find the nonce in every sec. If they don't find the nonce, they will change the configuration with the lowest data in the mempool. The algorithm works to solve these problem effectively.

Transactions and UTXOs in BlockChain: UTXOs stands for Unspent Transactions Outputs. In Bitcoin, the transaction lives after it has been executed until the other transactions built of the UTXOs. For ex, consider the transactions like,

Suppose, I want to buy a computer for 0.6 BTC. Before, You spent to the computer shop, you need to choose the transactions that link into an input. Any movement of money is the transactions in Blockchain. so, It can be described as,


           INPUT                                      OUTPUT
  0.7 BTC from Helen      Send 0.6 BTC to the computer shop.
                                            Then, 0.1 BTC back to myself.

Once the transaction is finished(Helen send to me of 0.7 BTC), it will no longer be UTXO. Now, you have new UTXO for the computer shop and to me as shown in the picture.

Then, I need to buy a bicycle for 1.0 BTC. Now, We need to construct the input as,


       INPUT                                      OUTPUT
0.1 BTC from Mark              Send 1.0 BTC to the Bike Shop.
0.5 BTC from Susan            The Bike Shop has UTXO for this transactions.
0.4 BTC from Sam

Now, I have only one UTXO of 0.1BTC. This is considered as my balance. There is a transaction fee in the blockchain. If you want your transaction to be accepted, you need to put the fee. The higher the fee, it will more likely to be accepted sooner. It can be calculated as the total input minus the total output and the difference is assumed as a fee. In the real world, we can look at the UTXOs  transactions that come from somewhere else that goes to other places and the amount. The tree chart that grows bigger when clicking the child.
       So, the wallet identifies all the transactions that ended up something coming to me and sees those transactions that still have UTXOs. Then, it adds up this amount and get the balance in your wallet.

The Private key, Public Key and Signatures: In the Blockchain, you can clearly see who is sending or receiving the money. Anybody can calculate the UTXO and may hack your money. So, you need the private key for the security of wallet. When you create a cryptocurrency, you are assigned a private key. This is your unique identifier. It is considered as the password to your bank account. From the private key, you can generate a public key. But, you cannot reverse the private key from the public key. You need to share the public key to others to send money. For ex, you want to send the message that can be text or anything. In cryptocurrency, it is the transaction. The private key combines with a message together generates the signature. Basically, the private key is used to sign the message. In Blockchain, there is a verification function algorithm. Anybody who has the message and signature, they can put them to the verification function with your public key. This will result to confirm or deny the transactions.
      In the Signature demo,  you can generate the random private key which will generate the public key. Similarly, In the signatures, when you edit your messages and click the sign button, the signatures will be created. In the verify, you can see the messages, signature and public key. They can use these 3 inputs to verify that the signature belongs to the holder of a private key behind the holder of the public key. It will not get verified when anybody changes the messages or put the fake signature.  You might see in the transactions tab, the messages have been replaced with the amount.

Public Key Vs Bitcoin Address: BitCoin Address is derived from the public key. It simply applied by the SHA256 function. As you know the sha256 function is deterministic. So, if you have the public key, you will always get the same address. It will never generate for 2 different public key to the same address. It is that address to ask the people to send money. Also, they can directly send to the public key as well. The sha256 function will provide additional protection for getting back your private key. So, if you have the bitcoin address, they can not get it back your public key.

HD (Hierarchically Deterministic) Wallets: HD wallets has the Master Private Key. The Private Keys are generated from the Master Private key. Then, the Public key uses the private key which uses for the Bitcoin Address. The private key and master private key are kept secure. You can generate as many private keys from the Master Private Key. It is very deterministic. It means you can regenerate the private key from the master key at any point in time. It is very useful when you send and receive money to put different public key and address. If the organization uses the Bitcoin for the products or services to run their business, they can use different private keys for each department from the Master Private key. From the Master Private Key, you can see all the transactions associated with any of the private keys. From the private keys, you can see the transactions associated with that address only. The Master Public Key will be useful in generating different public keys. The wallets will do all the things at the background.