NEW

Connect the world's APIs to Web3 with Chainlink Functions. Get started

Google Weather Oracle

You can use Chainlink to digest weather information using Google Cloud Public Datasets. We have a sample brownie repo showing how to interact with the contracts available in our gcp-weather brownie repo. More information on this oracle can be found in the following Google Cloud article.

Parameters and External Adapters Details

These jobs are using a custom external adapter. Please see the Google weather external adapter to see information about parameters that can be used with these jobs.

You will need to use the following LINK token address, oracle address, and JobSpec IDs in order to create the Chainlink request to this oracle.

Mainnet

Parameter Value
ETH_CHAIN_ID 1
ChainLink Token Address 0x514910771AF9Ca656af840dff83E8264EcF986CA
Oracle 0x92c08A635C7525505123F0F8e327C6Fa66E09a18
Rain JobID e9c41111b74f454695abd471806d9c6f
Hail JobID 941cb4bdd6e746cd933a37c8e92f2f98
Average Temperature JobID c6f853860b4f479fbda0910350d695b6
Generic JobID 0606a7c2811e4dbab659be400ecd41f9
Fee 1000000000000000000 (1 LINK)
Node Operator 0x6767eDa1C1d0070cEbdFE1CB3a55e4B63FA02C3E

Steps For Using This Oracle

  • Write and deploy your contract using the network details above.
  • Fund it with LINK
  • Call your request method

Create your Chainlinked contract

Import ChainlinkClient.sol into your contract so you can inherit the ChainlinkClient behavior. Below is a sample that can call the hail, rain, and average temperature jobs to fetch weather data from Bergen, Norway.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

/**
 * Request testnet LINK and ETH here: https://faucets.chain.link/
 * Find information on LINK Token Contracts and get the latest ETH and LINK faucets here: https://docs.chain.link/docs/link-token-contracts/
 */

/**
 * THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
 * THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
 * DO NOT USE THIS CODE IN PRODUCTION.
 */

contract Weather is ChainlinkClient {
    using Chainlink for Chainlink.Request;

    bytes32 public avgTempJobId;
    uint256 public avgTemp;
    bytes32 public totalRainJobId;
    uint256 public totalRain;
    bytes32 public hailJobId;
    uint256 public hail;
    uint256 public fee;

    event AvgTemp(uint256 _result);
    event TotalRain(uint256 _result);
    event Hail(uint256 _result);

    constructor(
        address _link,
        address _oracle,
        bytes32 _avgTempJobId,
        bytes32 _totalRainJobId,
        bytes32 _hailJobId,
        uint256 _fee
    ) {
        setChainlinkToken(_link);
        setChainlinkOracle(_oracle);
        avgTempJobId = _avgTempJobId;
        totalRainJobId = _totalRainJobId;
        hailJobId = _hailJobId;
        fee = _fee;
    }

    function requestAvgTemp(string memory _from, string memory _to) external {
        Chainlink.Request memory req = buildChainlinkRequest(
            avgTempJobId,
            address(this),
            this.fulfillAvgTemp.selector
        );
        req.add("dateFrom", _from);
        req.add("dateTo", _to);
        req.add("method", "AVG");
        req.add("column", "temp");
        sendChainlinkRequest(req, fee);
    }

    function fulfillAvgTemp(
        bytes32 _requestId,
        uint256 _result
    ) external recordChainlinkFulfillment(_requestId) {
        avgTemp = _result;
        emit AvgTemp(_result);
    }

    function requestTotalRain(string memory _from, string memory _to) external {
        Chainlink.Request memory req = buildChainlinkRequest(
            totalRainJobId,
            address(this),
            this.fulfillTotalRain.selector
        );
        req.add("dateFrom", _from);
        req.add("dateTo", _to);
        req.add("method", "SUM");
        req.add("column", "prcp");
        sendChainlinkRequest(req, fee);
    }

    function fulfillTotalRain(
        bytes32 _requestId,
        uint256 _result
    ) external recordChainlinkFulfillment(_requestId) {
        totalRain = _result;
        emit TotalRain(_result);
    }

    function requestHail(string memory _from, string memory _to) external {
        Chainlink.Request memory req = buildChainlinkRequest(
            hailJobId,
            address(this),
            this.fulfillHail.selector
        );
        req.add("dateFrom", _from);
        req.add("dateTo", _to);
        req.add("method", "SUM");
        req.add("column", "hail");
        sendChainlinkRequest(req, fee);
    }

    function fulfillHail(
        bytes32 _requestId,
        uint256 _result
    ) external recordChainlinkFulfillment(_requestId) {
        hail = _result;
        emit Hail(_result);
    }
}

Jobs

Rain (Bergen, Norway)

Tasks

  1. gcp-weather: Makes a call to the google weather dataset
    1. Parameters:
{
  "geoJson": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Point",
          "coordinates": [5.325622558593749, 60.3887552979679]
        },
        "properties": {}
      }
    ]
  }
}
  1. multiply: Multiples the output - set to 1000000000000000000
  2. ethuint256: Turns the result into a uint256
  3. ethTx: Sends the TX to the blockchain

Hail (Bergen, Norway)

Tasks

  1. gcp-weather: Makes a call to the google weather dataset
    1. Parameters
{
  "geoJson": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            {
              "0": [5.2796173095703125, 60.40673218057448],
              "1": [5.164947509765625, 60.383665698324926],
              "2": [5.17730712890625, 60.211509994185604],
              "3": [5.401153564453124, 60.27694067255946],
              "4": [5.6188201904296875, 60.436558668419984],
              "5": [5.526123046875, 60.42842688461354],
              "6": [5.3002166748046875, 60.5387098888639],
              "7": [5.238418579101562, 60.4951151199491],
              "8": [5.2796173095703125, 60.40673218057448]
            }
          ]
        },
        "properties": {}
      }
    ]
  }
}
  1. ethuint256: Turns the result into a uint256
  2. ethTx: Sends the TX to the blockchain

Average Temperature (Bergen, Norway)

Tasks

  1. gcp-weather: Makes a call to the google weather dataset
    1. Parameters:
{
  "geoJson": {
    "type": "FeatureCollection",
    "features": [
      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            {
              "0": [5.2796173095703125, 60.40673218057448],
              "1": [5.164947509765625, 60.383665698324926],
              "2": [5.17730712890625, 60.211509994185604],
              "3": [5.401153564453124, 60.27694067255946],
              "4": [5.6188201904296875, 60.436558668419984],
              "5": [5.526123046875, 60.42842688461354],
              "6": [5.3002166748046875, 60.5387098888639],
              "7": [5.238418579101562, 60.4951151199491],
              "8": [5.2796173095703125, 60.40673218057448]
            }
          ]
        },
        "properties": {}
      }
    ]
  }
}
  1. multiply: Multiples the output - set to 1000000000000000000
  2. ethuint256: Turns the result into a uint256
  3. ethTx: Sends the TX to the blockchain

Generic (Any Location)

Tasks

  1. gcp-weather: Makes a call to the google weather dataset
  2. multiply: Multiples the output
  3. ethuint256: Turns the result into a uint256
  4. ethTx: Sends the TX to the blockchain

Input Parameters

Required? Name Description Options Defaults to
geoJson A GeoJSON object containing the geographies to query
dateFrom The date to query data from (inclusive) in ISO 8601 format
dateTo The date to query data to (inclusive) in ISO 8601 format
method Which method to use to aggregate data in AVG, SUM, MIN, MAX
field Which column to fetch data from Data available
units What unit system to return the result in (conversions) imperial, metric imperial

Please see the Google weather external adapter to see information about parameters that can be used with these jobs.

Stay updated on the latest Chainlink news