Minimal Viable Oracle

screenshot of Minimal Viable Oracle

Minimal Viable Oracle

Connect your Ethereum smart contract to any real world API using the oracle pattern!

Overview:

The Minimal Viable Oracle (MVO) is a repository that demonstrates how to connect Ethereum to any real-world API using the oracle pattern. Smart contracts typically cannot access off-chain data directly, so the MVO provides a way to query external data that is not provided by common oracle providers in the Web3 space. In this tutorial, the MVO shows how to create a set of contracts that enable you to draw random cards from a standard 52-card deck.

Features:

  • Connect Ethereum to real-world API: The MVO shows how to connect Ethereum smart contracts to any real-world API using the oracle pattern.
  • Query external data: With the MVO, you can query external data that is not provided by common oracle providers in the Web3 space.
  • Draw random cards: The MVO allows you to draw random cards from a standard 52-card deck.

Installation:

To install and set up the MVO, follow these steps:

  1. Fork the project and clone it to your local environment.
  2. Install all the packages with npm i.
  3. Create a .env file and define the environment variables ALCHEMY_API_KEY_RINKEBY, ETHER_SCAN, and PRIVATE_KEY. You can use the example in .example.env as a reference.
  4. Open three tabs in the console.
  5. In the first tab, run npx hardhat run scripts/1_deploy-contracts.js --network rinkeby. This will deploy the contracts and verify them on etherscan. It may take up to three minutes. This script will also create a file called map.json that keeps track of the addresses of the deployed contracts. If it doesn't work on Windows, create the map.json file manually and insert the addresses of the deployed contracts. You can refer to map.example.json for inspiration.
  6. In the second tab, run npx hardhat run scripts/2_listen-to-oracle-requests.js --network rinkeby. This script fetches data from the API and sends it to the oracle contract. It runs in the background and won't log anything.
  7. In the third tab, run npx hardhat run scripts/2_listen-to-client-fulfillments.js --network rinkeby. This script listens for the ClientFulfillment event from the CardsClient contract.
  8. Finally, in the first tab, run npx hardhat run scripts/3_draw-cards.js --network rinkeby. This script triggers the "oracle flow" and draws 52 cards from a single deck without shuffling. You can adjust the number of cards to draw. Make sure you have some testnet Ether in your wallet, as each request sends 0.001 ETH to the oracle.

Summary:

The Minimal Viable Oracle (MVO) is a repository that provides a way to connect Ethereum smart contracts to external APIs using the oracle pattern. It allows you to query real-world data that is not provided by common oracle providers in the Web3 space. The MVO includes a tutorial on how to create contracts to draw random cards from a standard 52-card deck. The installation guide provides step-by-step instructions for setting up the MVO in your local environment.