Git Product home page Git Product logo

ae-oracle-pricefeed's Introduction

Aeternity Pricefeed Oracle

The ae-oracle-pricefeed is an example service that can be hosted and allows clients to query the current price of AE.

On startup of the service following tasks are being executed:

  1. The sdk-client is being initialized with the keypair provided via ./data/keypair.json (when using the command to host by hourself) or alternatively generates a new keypair if no keypair is provided
  2. The service checks if the account of the provided keypair has enough funds to run the oracle
    • if NOT it prints the respective information in the console and waits for respective funding (on testnet this can easily be done using https://faucet.aepps.com/)
  3. If the balance check is successful the service checks if the oracle is already registered
    • if NOT the oracle will be registered
  4. The service logs the oracle id to the console
    • this will be required for other contracts or services in order to query the oracle
  5. The service now periodically:
    • extends the TTL of the oracle if necessary
    • polls the node for queries that have to be answered
    • responds to queries if they exist

Host yourself

# checkout repository
git clone https://github.com/thepiwo/ae-oracle-pricefeed
cd ae-oracle-pricefeed

# build container
docker build -t ae-oracle-pricefeed .

# run, follow instructions to fund account, configure NODE_URL for other aeternity node
docker run -it --name pricefeed -v "$PWD/.data:/app/.data" -e NODE_URL=https://testnet.aeternity.io/ ae-oracle-pricefeed

Hosted on mainnet

There the ae-oracle-pricefeed oracle is running on mainnet:

Sample how to query the oracle using the SDK

  • implementation src/user/queryUsingSDK.js
  • running NODE_URL=https://testnet.aeternity.io/ ORACLE_ID=... SECRET_KEY=... node src/user/queryUsingSDK.js will initialize the SDK, query the oracle for the AE price in EUR and wait for the response of the oracle
    • it's required to provide ORACLE_ID and SECRET_KEY
    • the ORACLE_ID should be visible in the logs of ae-oracle-pricefeed service
    • for SECRET_KEY you should - of course - use your own key and you need to make sure that the account you are using has enough funds to query the oracle (for testnet you can use https://faucet.aepps.com/)

Query the oracle in a contract

  • Deploy PriceFeedQuery.aes and provide the oracle id of any compatible oracle for deployment
  • Call the queryAePrice function by providing a valid coingecko currency code, e.g. eur and of course the required oracle fee for the query
    • to check the query fee call the queryFee function
    • the function will return the oracle query id
  • Call checkQuery function by providing the query id in order to get the answer of the oracle

ae-oracle-pricefeed's People

Contributors

thepiwo avatar marc0olo avatar yinkaenoch 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.