Giter VIP home page Giter VIP logo

myoraclecontract's Introduction

Simple Oracle Project

This is a Orcacle contract for etherum network. I did this to remind myself that how oracle node works. There are two ways to update data on oracle contract:

Frontend(\web\oracle-app\src\App.js): Throgh the browser running ethers.js and react to send data to MetaMask.

Nodejs(\server\serverside.js): This script use pure web3.js and private key to signe transaction and send to target blockchain network.

Installation

Use the package manager npm to install packages.

npm install
cd server 
npm install
cd ../web/oracle-app
npm install

Usage

config the truffle-config.js and run

truffle compile
truffle deploy

Run the react web or the node script

Backend Passive

What is new ...

Recently I found a new way to write oracle from solidity's documentation and I decided to implement this method.

Passive Oracle

It is using a request queue to hold all requests and the backend server would received an event and do the work according to the request's content. After the server get the result, it will call the external callback function stored in the task queue in oracle smart contract. As the oracle server becomes a event-driven system, I name it Passive Oracle.

The issue from this method is that the oracle will need to pay the gas fee. To handle it, I initially designed a balance system to require user has to top up enough balance for the gas fee, but I fond it vulnerable to the dos attack, so I later changed it. Now it requires user to decide how much the gas fee would be comsumed and attach it to the query.

The code for this server is in this file Nodejs(\server\passiveServer.js):

Before start, you should change the privateKey and contractAddress. Don't hardcode them, just they to use env variable or build your own api to manage it.

cd ./server
npm install
npm run passiverServer

Third party api

Chainlink provides a decentrolised solution for oracle reqeust. I tried an example to get random number on Mumbai test network. To use it on different network, please change the contract addresses and the cost in the constractor. PS: sufficient amount of LINK coins must be transfered to the user's contract before use it.

I think thye met the same problem while calculate the callback's gas fee, and maybe that is why they need to introdue their own ERC20 token(ERC677 specifically). Also they mentioned that if the callback revert, the contract will be banned.

License

MIT

myoraclecontract's People

Contributors

b69liu avatar

Watchers

 avatar

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.