Tuesday, 30 April 2019

How to Deploy Solidity Smart Contracts into Ethereum Blockchain Technology?

     

          Ethereum by definition is an open source public service that uses blockchain technology to aid smart contracts and cryptocurrency trading without the third party. Ethereum offers two types of accounts externally owned. The public accounts which we own our private keys. The second one is the contract account, those are the accounts on which Ethereum developers deploy all kinds of smart contracts. Ether is the currency that we are going to use in the development of our smart contract and it is the main currency that sponsors most of the InitialCoinOffering(ICOs). It is expected that at some point in the near future it even beat bitcoin in the market cap. The key difference from the mother of bitcoin is the platforms ability to trade more than just cryptocurrency.
       Wallets: There are online wallets that should be your first choice if you're a security freak or you have a big amount of money invested. But, there are software wallets that have the official blockchain of the coin for instance of Ethereum. In order for the wallet to be functional, you have to synchronize your copy of the blockchain with the official one which depending on the coin might take a lot of your hard drive and time. The software wallet of Exodus provides a user interface that provides a pretty neat user interface that makes managing your assets easy and secure in a software wallet. When you first download and install it, you will be given a mnemonic phrase of 14 words that are your back up key when your PC gets broken or software gets deleted or any kind of situation in which you lose control of your software.
          There are hardware wallets that have nano ledger and hardware devices. The website called Nanoledger looks like a flash drive that has amazing security. If you lose your ledger you can always order a new one and put the coins from the last one to the new one with the mnemonic phrase. The advantage of the hardware wallet to the software wallet is pretty much unhackable.
        Finally, there are exchange wallets that you can use on the exchange accounts to store your assets. One of the biggest exchanges called Binance are getting the security measures better every day so that people can feel safer trusting their assets to the exchanges. For instance, after you make an account you'll notice that you have several layers of protection just to get inside your account. If you try to withdraw funds, you have to verify the transaction by quote send it to your phone or authentication email or whatever option you have in the wallet. The most important thing about handling cryptocurrencies is that your knowledge and only you take the responsibility about what happens to your assets and where you trust them to kept safe.

Solidity Smart Contract Constructor:  Here, we can see the sample contract, on top of every solidity file, there is a so-called version pragma which tells the latest version of solidity supported by the contract like,
     pragma solidity version ^0.4.24
      contract ContractName{
        * Variable Declarations
        * Mapping
        * Constructor
        * Functions
        * Modifiers
   }
There is so-called version pragma which tells the lowest version of solidity supported by the contract. After that, we have the contract and its name inside we can put the variables, mapping, constructors, functions, and modifiers etc., Remix is a great online IDE but we need some kind of Git control so we can commit our changes and rollbacks if needed. The best tool to do is Truffle, Ganache, and Visual Studio code. For setting this up, you need to install node.js as well. In order to install Truffle and Ganache properly on windows, you need to run the following function "npm install -g  -production windows-build-tools". After this is finished, we need to install Truffle on our machine.

Token Creation: Open remix and create a new contract named "basic token" on top as always. Let's define our version pragma type. Below this, we create our contract type contract. Let's define a mapping of addresses into 256 this is public and it is called balanceof, this will store all the balance of wallets that had the token. Now, we would want to create the constructor that would give the creator of the contract or the initial supply of tokens when we deploy the smart contract. Create the constructor unit of initial supply and inside the brackets let's set the balanceof msg sender to be equal to initialsupply. So, it gives the sender all the tokens. For the basic token, we need a function that can transfer the ownership of the token from one wallet address to another.

          Now, let's create a function called transfer that will receive address code to enter using uint256 called value. This function has to be public and return a boolean code success. Inside the function, we need to make some restrictions. Let's first check the sender has enough tokens to send( type require balanceof msg.sender greater or equal to value). Now that we know the sender has enough money, we need to make sure that we will not overflow that number that we have(type require the balance of receiver plus the value should be greater or equal to the balance of the receiver). Now, we are ready to transfer the money. First, let's deduct the money from the sender's account(type balanceof message sender minus equal value). Then, we add this money to the address we want to send them to(type balanceof to equals value). Let's return true. So the core function would know that everything was successful. This is the basics for token creation.

Deploying Token into Rinkeby Test Network: For this work, you need to get some Ether for the Test Network. Once, you have the Ether or go to Rinkeby and get your virtual Ether for testing purposes. There are many ways to deploy your tokens or contract to the test network.
              You can directly do this by Remix.  First, make sure you logged in your metamask and the Rinkeby test network. Once, you selected the Rinkeby, then compile the contract and ensure that there are no errors present in your code. After that, go to the run tab and select the injected web tree environment, then select the account you wish to use for deployment and deploy the contract. Don't forget to specify the initial supply when you deploy the contract. Now, the metamask should pop up and ask you for the confirmation of the transaction. Confirm and wait for the transaction to be validated.
        Another method is to select the website myetherwallet and login to your wallet with metamask and deploy the contracts directly. However, you need a bytecode of the contract in order to deploy it. To get the bytecode, go to the compiled code in Rymix and click on the bytecode. This will copy the bytecode to your clipboard and paste it over there.
         The other way is to select the website of walletethereum and we can deploy the contracts directly with code or bytecode. This wallet also connects with metamask so you can confirm the deployment. These are the methods to deploy the contract in Rinkeby test network.
         Now, let's go back to remix and find out our contract address. The contract deployment must be validated by now. So, go ahead and find the contract address on Eherscan. There we will have the address of the basic token. If you successfully deploy the tokens, You can add your tokens to different wallets and send the tokens to another address.

Adding Tokens to Wallets and Sending to Another Account: Let's open the website walletethreum and add the tokens to your wallet. In order to do that, open the contract, now at the bottom we have a section called custom tokens. Click on the watch token button and add our token. If you lost our token contract address, you can go to metamask and click on the contracts that you have created. You can distinguish the contract from the icon that we have on the site. Now, we have copied the contract address and go back to the website and paste the token contract address and give the name of the token. Then, enter the symbol as MFT and at the bottom are the decimal places of our smallest unit. It means how many decimals points our token has. Let's type 0 and say OK.  You have the token added to your wallet.
      Now, we can send the tokens to another address. Let's copy the address of another wallet from metamask. If you don't have one, just click create an account. Copy the wallet address and let's click on the send buttons inside the Ethreum wallet. Here, let's choose the tokens from our main account. In the To section, let's paste the address of the second wallet. Don't forget to choose the token name and this will cost us the amount of Ether to do so. Even if you're sending custom tokens, you still have to pay for the transaction in Ether. Make sure, you have enough Ether in your account. Now, let's click on Send. The metamask will show up asking for the confirmation of the transaction. Confirm and wait for the transaction to be validated. This we can check on the EtherScan that added successfully the token to that account. We can also send tokens to another account using the metamask.

Monday, 15 April 2019

4 things to know about Block Chain Technology and Crypto Currency


                Crypto Currency is a currency that does not exist in physical form. There are no coins or notes. It lives natively on the Internet. When the transaction takes place, participants who use Bitcoin, their computer specifically, validate the transaction and is recorded in the distributed ledger that is powered by Blockchain Technology. To have value, typically something must be scarce and must be accepted by others for payment like Gold, Diamonds, Silver is all deriving their value from being both scarce and expensive to mine. This is exactly translated into digital currency. The first characteristic is that there is only a limited amount of Bitcoins available. It is stipulated that there would be only 21 million Bitcoins. The second question is how a person or organization can acquire Bitcoin. Acquiring completely new bitcoin requires a unique type of mining like Gold.
         New Bitcoins are periodically released to the Bitcoin participant network and can be acquired by solving extremely complex mathematical puzzles. These puzzles take considerable computing power, so access to participate is limited. Computing power requires a lot of computers and a lot of power. This incurs a cost to miners. It is like mining oil in the wild ocean, only those with exceptional resources can participate to have a positive cash flow. Thereafter the value is calculated similarly to any currency by supply and demand. In simple terms, if the demand for Bitcoin is high, its value increases. If there is less demand, price drops. These Bitcoins can be used in all manner of organization, including small and big retailers accept Bitcoin. Wide acceptance of Bitcoin is the foundation for success.

Introduction to Digital Tokens: Token is something issued by an issuer and can be used in a specific marketplace and perhaps under certain conditions timing(In the physical world, think as casino chips).  The token has value because the context gives the value so once you have taken the token out of context or situation the value will fall ($100 casino chips is worth nothing outside of the casino). For simplicity, the token is used to mean any units recorded on any blockchain. There are 3 types of blockchain tokens,
1. Native Blockchain Tokens:  These are an incentive for the network participants and block creators to do their work. These are essential for underlying blockchain to work. For ex, BTC and ETH are used in bitcoin and Ethereum blockchain.
2. Asset-backed Tokens: Financial assets can be recorded as tokens. Financial assets are generally agreements between parties usually an issuer and the owner of the asset. Similarly, a bond is a legal agreement between the bond issuer and the bondholder. These agreements can be represented as tokens recorded on blockchains and distributed ledger.
3. Utility Tokens: The holder of a utility token can redeem the token from a specific entity of access to a product or service. It represents a liability of the issuing company because product and service become available, this entitles the token holder to redeem their token for that product or service.
         Initial Coin Offering( ICO) also called as token sales. They represent a new way for companies to raise money without diluting the ownership of the company or having to pay investors back. The ICO process includes Whitelisting, Funding Caps, Treasury and Exchange Listing

1. White Listing: In the whitelisting process, potential investors need to declare some of the key identity information(e.g, accept predefined terms and conditions, and provide the cryptocurrency address they indent to send funds from). During the token sale, the smart contract programmed to receive funds will only accept funds from those cryptocurrency addresses that have been whitelisted.
2. Funding Caps: You will often see soft and hard funding caps detailed in whitepapers. These are floors and ceiling to the funding amount the projects are willing to accept at any stage of the sales processes. A soft cap is the minimum amount of funds needed for projects to go ahead. A hard cap usually represents the maximum the project will accept.
3. Treasury: Projects that generally create more tokens than that are sold in the token sales and they keep a proportion behind in reserve. Once the token is listed, the project will have some idea as to the value of the tokens they hold in treasury. These tokens are held on the company's balance sheet and impact the equity valuation.
4. Exchange Listing: Some investors may buy tokens in the ICO to use the product, service or blockchain offered by the project. However, it is common for investors to buy tokens to speculate. As such an ability to sell the tokens - liquidity - important to investors. However, a listing of the token on crypto asset exchanges is the key event in the lifetime of an ICO because exchanges make the token more liquid.


Creating CryptoCurrencies: Your coin could emerge as a favorite, bringing you fame and fortune. You could become part of a historical shift from government-backed currencies. You might want to have your coin use an alternative proof of work and consensus mechanism. It's your cryptocurrency, you get to make the rules at the beginning. You could use your crypto to raise money for a new business idea. So, you'll use your coin with good intentions. But, there are a lot of scammers out there. If you buy scam crypto, there is no recourse. You've have lost your money.
      Another cryptocurrency generated on the blockchain is Ether. It is a really successful platform for writing smart contracts, the software program that runs on the blockchain technology without the need for the centralized software development platform. The Zcash is similar to bitcoin, but with a focus on transaction privacy. Litecoins are identical to bitcoin but with a faster transactional confirmation process. IOTA is a cryptocurrency developed specifically to help enable innovation in the Internet of things. The Coinmarketcap provides more information about other altcoins and specialty.
     You can create your own cryptocurrency by software fork. It is a copy of the existing code that powers bitcoin. Bitcoin is an open source that perfectly supports to copy and modify. Hundreds of cryptocurrencies were created this way. The copies are available from several sources that you can get from software repository in Github etc., Once you have the bitcoin source code, to make any modifications that require the programming skills in C++. The walletbuilders provides the free version that lets you create a crypto coin as a test service. In order to go live with your crypto, they do have a fee structure. The ethereum blockchain helps to create your crypto but you need deeper technical skills and there are some great support tools available.


CryptoCurrency Mining: The most important question in a cryptocurrency transaction is, does the payer, the person giving money have a cryptocurrency available to make payment. In the traditional
centralized system, if someone tries to write a check for an amount they don't have, eventually, the transaction will fail. How this can be achieved in Cryptocurrency? As you know, the cryptocurrency runs on the blockchain and the blockchain is a type of database is stored in its entirety on each participant computer. When one use in this blockchain wants to pay another user, a process of consensus must be met by all participants to allow the transaction. If the consensus is not reached, that is participants computer don't agree that the transaction is not legitimate, then it can't take place. The consensus is the governance that replaces the bank in a centralized model. We can say that mining is the process that enables consensus.
       For ex, Alice wants to pay Bob with cryptocurrency. Bob's address known to Alice. It's his public key. Suppose She wants to send 5 bitcoins, now the transaction is broadcasted to the bitcoin blockchain signed with her private key. Her private key associates Alice with the bitcoins she owns. When she broadcast her transaction, special users called miners are waiting to receive the transaction request. Miners validate the transaction and pass this information on to more users of the bitcoin blockchain, So they can also confirm the transaction. This is called consensus. The first miner validates and checks her sign of transaction with the bitcoin associated with her. Then, using the transaction request the miners used to solve a complex mathematical problem. It will take some input data from the transaction and transpose to predetermined output or target using a special algorithm. The first miner to solve the problem will be awarded the bitcoin. That miner then broadcasts the solution to the bitcoin blockchain. It is called proof of work which is further validated, then finally all participants of the blockchain where consensus is reached and the new transaction are approved and added as a block to the blockchain.


Succeeding with CryptoCurrency: First thing to recognize is that creating and nurturing a cryptocurrency is a long term endeavor. Assume that we want to create our own parameters. For example, How much currency will be available? Will we use for proof of work or some  other consensus mechanisms? Do we want more or less privacy around transaction? or Do we want to define it for certain usage say within the organization or industry? These are some high-level business decisions and technical parameters such as a hashing algorithm or block size are to be defined.                           Cryptocurrencies like Ether, Zcash, and Litecoin is doing a great job of creating and
fostering a variety of communities like the community of interest, meetups, social media footprints, events, blogger pickups, and online forum participation. This creates enthusiasts who further champion and promote new coin, particularly the founders are motivated, deliberate and committed to the long term. There is a strategy here and an element of luck too. So, put effort into getting the mining community established first. Miners create energy and momentum that will help build crypto coin credibility. Additional communities like merchants and exchanges are essential for the success of cryptocurrency. 
       Depending on the strategy, you might decide to work on having a particular merchant accept your currency. So, a good strategy, good timing and good luck really help. This is same for the exchanges. If your cryptocurrency can be bought, sold and exchanged for other cryptocurrencies or fiat currency, you've hit the jackpot. Finally, We must remind ourselves that the fundamental purpose of the money is to acquire products and services. A compelling cryptocurrency offers people an alternative form of money in the digital age. A cryptocurrency with tight integration, with exchanges and merchants where brokers and stakeholders view it as a credible mechanism for the exchange of value, will have a greater chance of success.