Full documentation on the OutLayer dashboard.
WASI component that fetches real-time weather data from OpenWeather API.
- ✅ Real-time weather data for any city
- ✅ Support for metric/imperial units
- ✅ API key via encrypted secrets (WASI environment variables)
- ✅ HTTP requests using WASI P2
- ✅ JSON input/output
{
"city": "London",
"units": "metric"
}Fields:
city(required): City name (e.g., "London", "New York", "Tokyo")units(optional): "metric" (default) or "imperial"
{
"city": "London",
"country": "GB",
"temperature": 15.5,
"temperature_unit": "C",
"description": "overcast clouds",
"humidity": 72,
"wind_speed": 3.6
}./build.shThe script adds the wasm32-wasip2 target if it is missing, builds in release mode,
and copies the result to ./weather-example.wasm.
Equivalent by hand:
# Add WASI P2 target
rustup target add wasm32-wasip2
# Build
cargo build --target wasm32-wasip2 --release
# Output: target/wasm32-wasip2/release/weather-example.wasmRequired: You must provide an OpenWeather API key to use this module.
- Get a free API key from: https://openweathermap.org/api
- Free tier includes:
- 60 calls/minute
- 1,000,000 calls/month
- No credit card required
cd ../wasi-test-runner
# Test with your API key
cargo run --release -- \
--wasm ../weather-example/target/wasm32-wasip2/release/weather-example.wasm \
--input '{"city":"London"}' \
--env OPENWEATHER_API_KEY=your_api_key_hereecho '{"city":"Tokyo","units":"metric"}' | \
wasmtime --env OPENWEATHER_API_KEY=your_api_key_here \
target/wasm32-wasip2/release/weather-example.wasmoutlayer upload target/wasm32-wasip2/release/weather-example.wasm
# prints SHA256 and: FastFS URL: https://test.fastfs.io/your.testnet/outlayer.testnet/<sha256>.wasm
outlayer deploy weather-example <FastFS URL>outlayer secrets set '{"OPENWEATHER_API_KEY":"your_key_here"}' \
--project your.testnet/weather-example --profile weather-productionOr in the dashboard (Secrets page): project your.testnet/weather-example, profile
weather-production, secrets JSON {"OPENWEATHER_API_KEY":"your_key_here"}, access AllowAll
(or custom conditions).
near call outlayer.testnet request_execution '{
"source": {
"Project": { "project_id": "your.testnet/weather-example", "version_key": null }
},
"secrets_ref": {
"profile": "weather-production",
"account_id": "your.testnet"
},
"resource_limits": {
"max_instructions": 50000000000,
"max_memory_mb": 128,
"max_execution_seconds": 30
},
"response_format": "Json",
"input_data": "{\"city\":\"Paris\",\"units\":\"metric\"}"
}' --accountId your.testnet --deposit 0.1Try different cities by changing input_data: {"city":"Tokyo","units":"metric"},
{"city":"New York","units":"imperial"} (Fahrenheit), {"city":"Paris"}.
# Get execution request ID from previous command output
near view outlayer.testnet get_request '{"request_id": 123}'{
"city": "London",
"country": "GB",
"temperature": 15.5,
"temperature_unit": "C",
"description": "overcast clouds",
"humidity": 72,
"wind_speed": 3.6
}┌─────────────────┐
│ NEAR Contract │
│ (client.near) │
└────────┬────────┘
│ request_execution(city="London")
↓
┌─────────────────────────────┐
│ OutLayer Contract │
│ (outlayer.testnet) │
│ - Stores encrypted secrets│
└────────┬────────────────────┘
│
↓
┌─────────────────────────────┐
│ Worker │
│ 1. Fetch WASM, check sha256│
│ 2. Decrypt secrets │
│ 3. Inject OPENWEATHER_* │
│ 4. Execute WASM │
└────────┬────────────────────┘
│
↓
┌─────────────────────────────┐
│ Weather Ark WASM │
│ - Read OPENWEATHER_API_KEY│
│ - HTTP GET to OpenWeather │
│ - Parse JSON response │
│ - Return formatted data │
└────────┬────────────────────┘
│
↓
┌─────────────────────────────┐
│ OpenWeather API │
│ api.openweathermap.org │
└─────────────────────────────┘
- Weather Bot: On-chain smart contract that provides weather data to users
- Conditional Payments: Release funds based on weather conditions (temperature, rain, etc.)
- Agricultural Contracts: Trigger actions based on local weather
- Travel Planning: Check weather before booking
Required: You must provide an OpenWeather API key via encrypted secrets.
- Get Key: https://openweathermap.org/api (free tier available)
- Free Tier: 60 calls/minute, 1,000,000 calls/month
- Storage: Store via OutLayer encrypted secrets (see Step 1 above)
serde/serde_json- JSON serializationwasi-http-client- HTTP requests (WASI P2)urlencoding- Encode city names for URLs
- Uses WASI Preview 2 (wasm32-wasip2) for HTTP support
- API key required: Must be provided via encrypted secrets
- Timeout: 10 seconds for HTTP request
- Supports all cities in OpenWeather database
"No weather data found":
- Check city spelling
- Try with country code: "London,GB" or "London,UK"
"Weather API error (401)":
- Invalid API key
- Check OPENWEATHER_API_KEY in secrets
"Weather API error (404)":
- City not found in OpenWeather database
- Try alternative spelling or nearby city
MIT