Git Product home page Git Product logo

intern2020a's Introduction

Ethereum Oracle

This is an implementation of an Ethereum oracle using web3. An oracle is simply a messenger which relays data from one source to another, in this case a number is fetched from an API and this is relayed to a smart contract on the ethereum blockchain via the "setNumber" function in the sample smart contract.

Dependencies

  1. Node.js
  2. NPM
  3. Web3
  4. node-fetch

Code Logic

Oracle.js consists of 2 core functions:

  1. main: This function fetches data from the api, which in this example is the average gas price for mined transactions on the main ethereum network. This is then set as the input for the setNumber function in the deployed sample smart contract. This input is set as the object for the second function (sendTx).
  2. sendTx: This function sets all the parameters for the transaction, signs the transaction and sends the transaction.

Implementation

In order to deploy and test the oracle:

  1. Clone the repository.
  2. Set up an ethereum wallet with ropsten ether (metamask is easiest).
  3. Deploy "sample.sol" (remix is easiest).
  4. Obtain a provider for the Ethereum network, you can run your own node via mist however for simplicity we are using Infura which is a public gateway to the blockchain. Sign up and you will be provided with an API key.
  5. Edit oracle.js as directed by the comments in the script. You will need: your infura API key, your ethereum wallet's private key, the smart contract's ABI (sample.sol ABI has been provided), and the address of the deployed contract.
  6. Run the oracle: cd into the directory and run command "node oracle.js".

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.