Skip to main content

Private Oracle Example

Private Oracles are currently available on a case by case bases, please get in touch if you have a usecase for private data integration. General availablility soon!

This project demonstrates how to create and deploy a weather oracle using VIA's messaging protocol. The oracle allows smart contracts to request weather data for a zipcode, which is fetched by an off-chain node and returned to the contract.

Prerequisites#

Before you begin, make sure you have:

Project Structure#

quickstart-oracle/โ”œโ”€โ”€ contracts/โ”‚   โ””โ”€โ”€ WeatherOracle.sol    # The oracle contract with request/response functionalityโ”œโ”€โ”€ scripts/โ”‚   โ”œโ”€โ”€ deploy.js            # Deploy script using ethers v6โ”‚   โ””โ”€โ”€ request-weather.js   # Script to request weather dataโ”œโ”€โ”€ oracle/โ”‚   โ”œโ”€โ”€ index.js             # VIA Project Node implementationโ”‚   โ””โ”€โ”€ features/โ”‚       โ”œโ”€โ”€ index.js         # Features registryโ”‚       โ””โ”€โ”€ WeatherOracle.js # Weather oracle feature implementationโ”œโ”€โ”€ network.config.js        # Network configurationโ”œโ”€โ”€ package.json             # Project dependenciesโ”œโ”€โ”€ .env.example             # Example environment variablesโ””โ”€โ”€ README.md                # Project documentation

Step 1: Clone & Setup#

# Clone the repositorygit clone https://github.com/VIALabs-io/quickstart-oracle.git && cd quickstart-oracle
# Install dependenciesnpm install
# Create a .env file with your private keyscp .env.example .env

Edit the .env file and add:

  • Your private key for deploying contracts (PRIVATE_KEY)
  • Your node private key for running the oracle node (NODE_PRIVATE_KEY)
  • Optionally, your OpenWeatherMap API key (WEATHER_API_KEY)

Step 2: Deploy Your Oracle Contract#

node scripts/deploy.js

Step 3: Edit oracle/index.js#

Edit the oracle/index.js to set the deployed contract address which can be found in deployments/ directory.

Step 4: Run the Oracle Node#

node oracle/index.js

Step 5: Request Weather Data#

node scripts/request-weather.js 90210

This command requests weather data for the zipcode 90210 (Beverly Hills). The script will:

  1. Send a transaction to the WeatherOracle contract
  2. Wait for the transaction to be confirmed
  3. Poll for the weather data to be received
  4. Display the weather data when it's available

๐ŸŽ‰ Congratulations! You've successfully built and used a private oracle.

Next Steps#

Need Help? Join our Discord community for support and discussions.