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.
#
PrerequisitesBefore you begin, make sure you have:
- Node.js (v20+) and npm
- Git
- Testnet tokens for Avalanche Testnet
#
Project Structurequickstart-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 Contractnode scripts/deploy.js
#
Step 3: Edit oracle/index.jsEdit the oracle/index.js
to set the deployed contract address which can be found in deployments/
directory.
#
Step 4: Run the Oracle Nodenode oracle/index.js
#
Step 5: Request Weather Datanode scripts/request-weather.js 90210
This command requests weather data for the zipcode 90210 (Beverly Hills). The script will:
- Send a transaction to the WeatherOracle contract
- Wait for the transaction to be confirmed
- Poll for the weather data to be received
- Display the weather data when it's available
๐ Congratulations! You've successfully built and used a private oracle.
#
Next StepsCreate Cross-Chain Tokens
Learn how to create tokens that can move between different blockchains.
Create Cross-Chain NFTs
Learn how to create NFTs that can move between different blockchains.
Learn About VIA Labs Architecture
Understand the technical details behind VIA Labs' cross-chain infrastructure.
Need Help? Join our Discord community for support and discussions.