camronh / StockBets-PoC

Stock Betting Smart Contract - Bet on stock prices by calling an API from a smart contract!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StockBets

A Proof-of-Concept that uses Airnode to send API requests from a smart contract to query data directly from DxFeed's public stock price API.


Under the Hood

Airnode RRP Flow White

More detailed Diagram Here

This PoC illustrates how easy it is to set up a contract to make API calls to an API that is running an Airnode. The process goes like this:

  1. An Airnode RRP contract has already been deployed by the API3 team on all of the Ethnets. We will be using the Rinkeby RRP. This is where our Airnode will expect us to put all of our requests.

  2. An Airnode that is configured to read from the RRP from the first step and to call the DxFeed API has been deployed to AWS.

  3. We have already deployed, and sponsored our Betting Contract, to allow access to the gas wallet Airnode will use to return the response on chain. We have hardcoded 1 gas wallet for this PoC. In production, you could allow for each user to have their own gas wallet, but for now anyone can top up this wallet.

  4. The GUI connects to the Betting Contract from step 3. Since all of the Airnode params are hardcoded into the contract, the end user can interact with the makeBet and callBet functions without needing any Airnode knowledge.

  5. An Airnode Request is made when using makeBet that requests the current TSLA price. The response is stored in a Bet struct in the contract. After 24 hours, the user is allowed to call their bet. This will send the same request and compare the price between yesterday and today from the response.

Structure

  • Hardhat - All of the Smart Contracts used in this PoC.
  • Airnode - Everything you need to run an Oracle.
  • Front End GUI - For easy interaction with the Betting Contract

Instructions

If you are attempting to run the code manually/locally, you only really need to do the following:

  1. Start up your Airnode
yarn start-airnode
  1. Set up blockchain

  2. Start up your Front End GUI

Recommended Reading

  1. Betting Contract - The Smart Contract that makes the API request. We put the request parameters on chain for immutability.

  2. Airnode Config - Your configuration for Airnode. Contains the mapping of the DxFeed public API endpoints and some chain info. This combined with the secrets.env are all you need to run Airnode.

  3. Front End Scripts - By including all of the Airnode parameters in the Betting Contract, the end user will only need to provide their bet direction (higher/lower) and their bet value.

About

Stock Betting Smart Contract - Bet on stock prices by calling an API from a smart contract!


Languages

Language:Vue 47.5%Language:JavaScript 27.6%Language:Solidity 21.2%Language:HTML 2.5%Language:Shell 1.2%