Giter Site home page Giter Site logo

phamvancam2104 / ethereum Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blockchain-demos/ethereum

0.0 2.0 0.0 160 KB

Collection of demos for interacting with the Ethereum Blockchain

License: The Unlicense

Jupyter Notebook 99.21% Dockerfile 0.53% Shell 0.26%

ethereum's Introduction

Ethereum Blockchain Demos

Collection of demos for interacting with the Ethereum Blockchain

Pre-reqs: To access the Ethereum Blockchain, we'll be using geth, the official Go Ethereum CLI client. It is the entry point into the Ethereum network (main-, test- or private net), capable of running as a full node (default) archive node (retaining all historical state) or a light node (retrieving data live).

Starting a ethereum/client-go container:

docker pull ethereum/client-go:v1.8.3

docker run -d --name ethereum-node \
-p 8545:8545 -p 30303:30303 \
ethereum/client-go:v1.8.3 \
--syncmode light \
--rpc --rpcaddr 0.0.0.0

This allows you to view and query events from the blockchain locally via a number of tools/bindings:

  • cUrl

    curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' -X POST http://localhost:8545
    
    {"jsonrpc":"2.0","id":83,"result":"0x51ed3f"}
    
    
  • python web3

    from web3 import Web3, HTTPProvider, IPCProvider
    web3 = Web3(HTTPProvider('http://localhost:8545'))
    
    # Retrieve the last block number available from geth RPC
    currentblock = web3.eth.getBlock('latest').number
    

Demos


Background

When most people think of "Blockchain", they think about Alice Sending Bob 2 coins, and that transaction being recorded on a public ledger.

On the Ethereum chain however, the public ledger holds both currency transfers AND code (Smart Contract) execution logs.

Not all HelloWorld are the same

In a traditional object oriented language, running a "HelloWorld.exension" should result in the same output whether Alice runs the file or Bob runs the file.

On the ethereum blockchain, when a program is written, it must be "deployed" to the blockchain by a user's wallet. This means that although 2 ".sol" programs may have 100% identical code, they will each by pushed to the blockchain and have a unique "Contract Address", along with some metadata such as the user who deployed the contract.

Here we will use remix.ethereum.org, a free Solidity Web Compiler, to showcase a simple Hello World smart contract deployed by Alice vs Hello World Deployed by Bobbie

  • HelloWorld.sol deployed by alice's wallet 0xca35b7d915458ef540ade6068dfe2f44e8fa733c:

  • HelloWorld.sol deployed by Bob's wallet 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c:

Even more interesting, once a "smart contract" is deployed to a "contract address", EACH FUNCTION in the smart contract has a unique "MethodID" and "Topic" which can be used to see when that given function belonging to the smart contract was invoked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.