Skip to main content

Easiest way to understand how the Ethereum Smart Contract work



Ethereum is one the fastest growing block chain with ever growing eco-system. It's beautiful in that, unlike Bitcoin, it's not just a currency, it's a complete platform for Decentralized Application (Dapp). Ethereum as currency just being one of the many application of the platform. Sheer enthusiasm about this currency in recent times has caused emergence of tonnes of technologies around it. Once you start reading about ethereum you will be hit by technical Jargons at 1 jargon per minute speed.

Hence, this article is an attempt to help you visualize one aspect of the Ethereum system, ie. how smart contract work.

Imagine you want to create a bank where users can manage their accounts. Also, any other third party bank should be able to integrate with your super awesome bank. So, you create a following piece of code.

class Bank{
    Map<String, Double> accountMap;
    public void transferTo(String accountNumber, double amount){
        double balance = accountMap.get(accountNumber);
        accountMap.put(accountNumber, balance + amount);
    }
    public void withdrawFrom(String accountNumber, double amount){
        double balance = accountMap.get(accountNumber);
        accountMap.put(accountNumber, balance - amount);
    }
    public double getBalance(String accountNumber){
        return accountMap.get(accountNumber);
    }
}


But this is of little use because account state is stored in RAM (heap), and is volatile. You will need to persist it in database. You will have to host it publicly and make sure it's up 24x7.

Ethereum handles it by replicating same program on thousands of machines. Imagine as if each program shares the state of the member variables with each other. Interested people can create their apps around your program and they can pass on queries from their system to your intelligent bank.

What we have written just now is essentially an Ethereum smart contract (except that it should be translated into Solidity, the Ethereum programming language)

Hope this gives different perspective in the understanding of Ethereum Smart Contracts.

Suggestions / queries are most welcome.

Comments

  1. Great Article
    Cloud Computing Projects


    Networking Projects

    Final Year Projects for CSE


    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete

Post a Comment

Popular posts from this blog

Auto Scaling DynamoDB

Those of you who have worked with the DynamoDB long enough, will be aware of the tricky scaling policies of DynamoDB. It allows user to explicitly set requests per second (units per second, but for simplicity we will just say request per second). User can do so for read as well as write operations. Anytime user can increase or decrease the provision capacity from DynamoDB web console and it will reflect immediately. Sounds all good....... Or not? What if you set provisioned capacity to 50 req per second but load on the server crosses 100 req per second? Requests gets throttled!! Mostly times out. What's worse? This can cause requests getting queued up in your web server. Which can potentially bring your entire server down. What if you set provisioned capacity to 1000 req per second but load on the server is only 100 req per second through out the day? You lose your hard earned money for remaining 900 req per second. What if you set it to 1000 req per sec and then realis

StackDriver Integration with AWS Elastic Beanstalk - Part 2

Eb Extension Config Our goal is to create a configuration such that, it can run on any elastic beanstalk instance. It should send production and non-production logs to two seperate Stackdriver projects. Adding monitoring for new log file should include minimal changes at best. If you have used Elastic Beanstalk before, probably you will be familiar with eb-extensions scripts. These are the set of commands those run everytime application is deployed on the EB. Step 1: Create folder .ebextension in your WEB-ROOT directory.  EB by default looks for ".config" files under .ebextension directory and executes on app-deployment. Add sub-directory called "stackdriver" under .ebextension directory that you just created. Step 2: Add google-fluentd.conf file in stackdriver directory.  Fluent-d agent runs on this configuration. This file tells the fluentd where to look for log files. Following sample file configures fluentd to check for app.log and billing.log files.