Sunday, 31 March 2019

How to Integrate DApps and Cryptocurrency into Ethereum Network?

        There are two basic elements to be implemented when you build a DApp on Ethereum Blockchain. Those are smart contract and web interface. The smart contracts or multiple smart contracts that allow for customizing the access to Blockchain where we can store our data. Solidity helps for writing the smart contract in the Ethereum network. It also allows depositing ether into the contract only to be released by the third party. We could also modify to have the funds released based on some kind of chain event that won't require any user interaction. But, it is necessary to build a user interface that allows sending ether from one address to another.
Interacting with Ethereum Network:
        The basic difference from the traditional web application is that the Sequence it executes like User interface -> Smart Contracts  ->  BlockChain whereas the traditional application works as Front-End -> API -> MySql database. The heart of Ethereum power is EthereumVirtualMachine(EVM). It is co-located with full Ethereum Blockchain so anyone can download and run the node. EVM is the app server that's going to handle processing smart contracts and programming functionality. The other services through these nodes are SWARM for hosting files and Whisper for messaging in DApps. Every node runs the EVM. This syncs data to maintain the security and consensus of the Blockchain. Because of this, there is high fault tolerance and zero downtime which ensures immutability and block censorship.
Properties of EVM:
   1.  It is a run time Engine that processes smart contracts. Contracts are stored in byte code in blockchain so they can be compiled prior to deployment the blockchain. Also, it is limited access to other contracts.
   2. No Inherent access to file system, networks or processes
   3. Usually written in solidity. The other options available are Lisk, Bampoo,Viber.
   4. EVM does have non-persistent memory so you can run the variables that are used during the execution of a function and the function is completed executing they will no longer exist in the memory. If you want to maintain the data you can create the variables which will store the data in key-value pairs onto the blockchain.

     There are the number of different EVMs available that you can check at Github latest releases. The key to choose EVM is to an active community and contribute to those features that are available within that EVM. The Truffle and Ganache provide more of the visual interface in real time that how the wallets are changing and where the ether is flowing. Geth helps to run EVM on a testnet or mainnet.  The block explorer like Etherscan provides information that anything happened in the blockchain, whose mined them, what the block reward and how many transactions are in them etc., You can drill down the contracts and transactions that will provide you the information about from address, to address, current balance, the type of contracts,  bytecode processed by EVM, errors in executing transactions and warnings etc., In the contract, when you transfer tokens it actually sends it to contract and the contract is mediator for sending whatever the token is back and forth.

Building Simple DApp UI:  Ethereum Blockchain accepts programming instructions called smart contracts that are written in a language called solidity. Any Ethereum user can write smart contract put into the Ethereum network. This contract is performed by nodes on the Ethereum network which forms EVM. An application written using smart contract is called a distributed application or DAPP. The contracts creator pays participants in the Ethereum network to process that application using cryptocurrency called Ether. Your programming to be rock solid because you can't really change the smart contract once it is in motion. Fortunately,  the wallet's that are available on includes options to try out your code on test network before any real money is involved so that you can check and double check your code for smart contracts.
       This is the basic interface for interacting with our smart contract. It used the bootstrap for simple layout purposes and using the jquery, we can interact with Ethereum network. It allows to
enter the Ethereum address and where we are sending it to and there is an approval process in the interim. This application will help you to deposit the ether into the contract. Also, we have the ability to get the balance and see who the approver is. Finally, we have the ability to approve the transaction which will clear the data out of the smart contract and send it to the recipient.

     It is all set up. Now, we are going to write our scripts to do all the action. Web3.Js is the javascript library that will interact with DApp. It is the standard for how we are going to interact with our client-side applications to the Ethereum network. Also, you can see different packages which allow interacting directly with blockchain. If you want to enable interaction with Metamask, Metamask should be injected its own web3.js. Web3 is easy to implement and enables to do a lot of interaction with Ethereum blockchain. It can create new accounts, send Ether, add signatures to transfers, get balances from accounts, get transactions and transaction IDs etc.,

Deploying to Ethereum Network: Once you developed and tested your app, the next step is to install Geth on windows. Once you installed in your system, you need to create your accounts
that you use for testing and confirm the Passphrase that will give you the address. This is how connecting and synching to Ethereum main network. If you want to sync to Ropsten testnet, create an account in the command line interface and say geth -testnet account new. Then, we are going to type our passphrase and get our address. This is our Ox address. Now, we can go ahead and fire up Geth. You just put your address in and say send test ether. Now, you can see that Ether sent to your address with the 0x and shows the transaction that's currently pending. It is the ropsten version of Etherscan and not the main network. Once your server syncs up, it pulls the transaction and you can see the ether in your account. Deploying to the main net is exactly the same process. The difference is we're going to have our local network sync with the main net and not the ropsten net. So make sure that network id matches the main net with our truffle settings of Ethereum client. The most popular Ethereum client is Go Ethereum called as Geth. This is going to run a node of Ethereum, as well as EVM on your machine that allows you to migrate smart contracts to different networks.

Initial Coin Offering(ICO) of a Company: It differs from the Initial Public Offering(IPO) that the company floats its shares on the stock market for everyone potentially to buy. It is a fundraising mechanism that is regulated and tried. Usually, it occurs at the later stages of the businesses or after several rounds of funding. The ultimate goal of this company is getting the stock market or essentially selling a company's part of the shares on the stock market. Whereas ICO's most part isn't regulated and unregulated. It is obviously the early days of the crypto-based platforms. It usually occurs at the early stages of a company of an idea. Usually what happens is a white paper published along with their idea. The white paper from the technical point of view explains their concept of how their ideas going to occur.and what we are doing with less of a marketing document.

            The first thing you need to know is what does it sells. It sells new cryptocurrency tokens that underly the new products. So, you know that new products that our company has that sell the new tokens. This is exchanged for cryptocurrency of Ether, Bitcoin or something else. Most of the time the Ether or Ethereum based platform that you do is ICO. This is great for engaging with the company or the community with more about the personal touch. It is more like crowdfunding platforms such as Kickstarter and Indiegogo have given way to companies like Oculus where you don't give the share in your company. What you do actually is sort of just like give rewards. It is not like shares and you don't have control of a portion of the company but can be traded. Also, you can spend tokens on the stuff. Sometimes, it can be used on the actual company's product itself.
           There are fraudsters that they publish 10 to 20 pages with the marketing presentation of documents and not actually doing technically. So, there are institutions that are trying to fix this in certain conditions in place by having an escrow account that needs several signatures by different private keys to be able to get the funds and use them impartially.

Friday, 15 March 2019

What are the basics of Developing a Blockchain Applications (DAPPs)?

          The BlockChain is fully distributed peer to peer software network which makes use of cryptography to securely host applications data and easily transfer digital instruments of value that represents the real world money. Cryptography is an art of communication via coded messages. The Bitcoin and Ethereum are used to conjure one secure computing environment of thousands of similar machines running with no single authority and no single user. The term Ethereum refers to 3 different things. Those are,
1. The Ethereum Protocol
2. The Ethereum Network
3. Creating Decentralized Applications

Decentralized Applications:
DAPP is an application that runs on the blockchain. The blockchain enables apps to run without having a central location like web URL. Whenever we go to a web URL  or mobile app, it is going to interact with core functionality at a central point. All of the functionality will reside on servers or virtual servers and all of the data will be stored within that environment. Because of the centralized location, it is vulnerable to a distributed denial of service attack.  Every time you use centralized location, you're surrendering trust, paying fees, and giving up the data to whoever is operating that central location. When you look at the DAPP, everything is hosted through the Ethereum network. Because of that, you can access DAPP from any node that can access the blockchain. This opens up the huge global network of the Ethereum network.
        Decentralized applications are basically formed with the base of a blockchain. The blockchain is a fully distributed network that uses cryptography to host the applications. Decentralized applications like Ethereum which include blockchain as a data structure. Decentralized applications are those that every node is connected to the other node and every node work independently and does not rely on any other node. Applications which spread along multiple servers instead of focusing on a single. For ex, Bitcoin is the decentralized application which uses the data structure of the blockchain. The nodes of decentralized applications are distributed to which it becomes difficult to protect and prevent all of this centralized network from making any invalid or unauthorized changes to the application. Each and every decentralized application should generate tokens on the basis of a cryptographic algorithm which acts as a proof of value. DAPP(Decentralized Application)s are internet application whose backend comprises of the centralized architecture. It is the architecture that no single node has complete control or data that includes different data structures and modules which comprises of protocol for creating the web application.

An advantage of DAPP:
1. DApps are fault tolerant. The nodes and peers of the application are distributed by default and hence there is a meager chance of failure.
2. It prevents violation of net censorship and ownership as there is no authority can pressurize to append any changes.
3. DApps are IP independent. It can't access via particular IP address or domain. So, any official authority can not track any individual and shut them in particular case of emergency.
     Distributed applications are beneficial when application data and the volume of traffic increases at that rate. Centralized applications create an issue with the performance of the product in website and applications downtime. DApps overcomes the challenge to receive or achieve high availability of data. The basic examples of distributed applications are Facebook, Dropbox, and Slack.
The concept of Mist Browser: In the world of cryptocurrency software, there are essential types of nodes which are called wallets and footnotes. Wallets are software applications for desktop or mobile devices that hold the key to the EVM(EthereumVirtualMachine). It holds the money for all transactions like a debit card, or credit card or cash will be kept inside the wallet. Wallets also hold the keys. Keys correspond to an account by long account address. In Ethereum account, it does not store your name, your personal information. Anyone can create Ethereum account by connecting to the network with the help of client and that Ethereum client is mist browser. You can generate many clients the way you need it. Here, the cryptocurrency transaction is the settlement of particular trade.
    Mist is the client side module which manages all the necessary transactions. It is compatible with Windows, Linux, Mac and you can check out at Github for latest releases. It includes some plugins to support the transaction that can take place. Once the installation successful in your system, you can see the wallets and can create the contract. This contract is associated with Ethereum wallet.

Ethereum Virtual Machine: EVM is a single global 256bit computer in which all the transactions are local on each node of the network and executed relative synchronously. It is composed of lots of smaller computer. A giant computer has a node or wallet application can access makes it move
arbitrarily large amounts of value. A virtual machine is an emulation of a computer system by another computer system. It is based on the same computer architecture as the target of their emulation. This can be created as software or hardware or both. In the Ethereum context, the smart contracts are the agreements between accounts to render a transfer of ether when certain conditions are met and the assets in smart contracts are moved automatically. There are the various set of blocks and the first set of a block is called the genesis block which is also called as a canonical block. The transactions in the EVM is cryptographically signed data pocket storing a message which tells them EVM to transfer ether, create a new contract, trigger existing one or perform some calculation.

Introduction to Solidity: Solidity is the contract oriented, a high-level language for implementing smart contracts. It is influenced by python, C++, javascript and is designed to target Ethereum virtual machine. You can install a compiler for Mac, Windows, Linux or try it on the web with Remix. Take a look at the website State of the DApps to know others have built with Ethereum and solidity. Ethereum is the platform to build DAPPs and solidity is the language, Solidity supports types, inheritance, and libraries and aim at the EVM.

 Solidity Basics:  The first thing you need to do is go to Remix and feel free to erase everything and start programming with import solidity and the way you do that is keyword pragma, which means that we are going to load only once with the version number. Once you have imported the solidity file, then you can import any other file. Then,What you do is set up the contract. In the contract, you need to put the variables, functions, and code inside the contract.
    Contracts in solidity are similar to classes in the object-oriented language. It can contain state variables, functions, events, structype, and enum types. First, declare the state variables and the word state means that the current status of that variable. Also, you have functions and modifiers. Modifiers are conditions to the functions or conditions before we run the function. The last thing in the contract is an event. The events are basically the javascript events or any kind of programming language events.

Creating Simple Contracts Using Solidity: We can use remix to work on this example and leverage the compiler to run the contract afterward. First, we will create few variables and create an address which is the owner variable. We need an address because most of the contract comes with an address. Then, we will introduce a new constructor. Here, we are building the instance of the variable. The global variables that are available in messages, and then the properties that were coming from the messenger. The message will come with value, that we will pass it to money. Deceased will set false initially and pass the owner variable to the message sender. And, Set an array of address that we use and we call this as array wallets. Use the mapping to pass the integer to addresses inside of the inheritance.
    Now, you need to set the conditions of the contract with modifiers. Modifiers are conditionals to run the functions. So, put as many modifiers as we want as long as they are conditions to validate things that you want before you run the contract. Finally, go ahead do the functions that will actually run your contracts. This function will be public and will need one owner. Here, we are adding to wallets with push function. We are setting up the contract here, and then we are using inheritance and we create an array that holds the wallet with the inheritance.

        Finally, Test our sample contract to make sure that compiles and have a green compilation. Then, go to the run tab and make sure javascript VM is selected. the gas option is the cost to run the smart contract on Ethereum. For the test scenario, set the value of the contract. Now, We have the contract inheritance and we can deploy the contract and check the console to see that we have successfully created the contract and the contract on the righten side. In the deployed contracts tab, you can see the inheritance, deploy and setup. We need to set up the amount for each inheritor. Grab the contract address in the console and put in the setup such as address (comma contract of) 100 and click the setup. So, when you click this. it is going to set deceased true and then pay the money to the people in the wallet. This is how the smart contract work inside solidity.