GithubHelp home page GithubHelp logo

aazzii20 / ethereum-oracle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arilucea/ethereum-oracle

0.0 0.0 0.0 235 KB

Simple upgradable etherum oracle to get information from APIs an push it into a smart contract

License: GNU General Public License v3.0

Python 29.98% Go 23.55% TypeScript 16.37% Solidity 30.10%

ethereum-oracle's Introduction

Simple Ethereum-Oracle

Given an URL to the contract using the "makePetition" function, it will answer with the requested information from the API and store it on the caller contract using the "__callback" function. Currently the system only supports GET requests.

Configuration

In the config.json file change the the parameters needed:

  • rpcURL: endpoint of the network (in the example using Infura).
  • socketURL: endpoint of the socket to capture the event (in the example using Infura).
  • oracleAddr: address of the oracle contract.
  • senderAddr: address used to send the answers.

The private key of the address used to send the answers and API key of infura, both are used in the scripts are keep as enviroment variables.

How to use it

  1. Deploy ContractOracle
  2. Change the parameters on config.json
  3. Start the script Catch-Response
  4. Caller contract must implement the "__callback" function.

Petition examples

First must be indicate the the url, after it there must be an "(" containing the chain of elements to get the one we want from the response if the field is a string a "." should be before the value, if the field is a number there should be a "|". After the last element the brackest have to be closed and inicate if the response is a json.

"https://api.coinbase.com/v2/prices/spot?currency=USD(.data.amount)json", "URL/GET"

We want to get the Bitcoin price in USD an store it in our contract. We call this API https://api.coinbase.com/v2/prices/spot?currency=USD json as response.

{
    'data': 
            {
                'base': 'BTC', 
                'currency': 'USD', 
                'amount': '11221.685'
            }
}

To make the petition we have to indicate the field we want from the json ("amount"). The petition to the oracle should be the following.

"https://api.coinbase.com/v2/prices/spot?currency=USD(.data.amount)json", "URL/GET"

The fields we want to filter are "data" and inside it "amount" both are strings so both are precided by a "."

The "__callback" function of the caller will recieve a '11221.685' in the form of a string.

ethereum-oracle's People

Contributors

arilucea avatar dependabot[bot] 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.