Skip to content

Instantly share code, notes, and snippets.

@thodges-gh
Last active January 4, 2024 12:59
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thodges-gh/26b2f745934d7113bdffc0f91b36d343 to your computer and use it in GitHub Desktop.
Save thodges-gh/26b2f745934d7113bdffc0f91b36d343 to your computer and use it in GitHub Desktop.

Google Weather Demo

Contract: https://goerli.etherscan.io/address/0x6b705fc5c425be07ebe59d09aa9fd2c0df88cab4

Test transactions:

Deployment params (Goerli):

  • _link: 0x326c977e6efc84e512bb9c30f76e30c160ed06fb
  • _oracle: 0x292D4Cc76c00D9682230fC712F6B1419eF88aC9b
  • _fee: 100000000000000000

Deployment params (Mainnet):

  • _link: 0x514910771af9ca656af840dff83e8264ecf986ca
  • _oracle: 0x049Bd8C3adC3fE7d3Fc2a44541d955A537c2A484
  • _fee: 100000000000000000

Fund the contract with LINK before calling request methods.

Job IDs (Goerli):

  • Generic _jobId: 0x3461343138656439333630323462343161393331353436323934363862393664
  • AvgTemp _jobId: 0x3137383932643664373132343463633038356463313634353861633633636437
  • TotalRain _jobId: 0x3138636635616536653961373439663238656436626461636265306137356564
  • Hail _jobId: 0x3436666333393464336438313431333962316333613638376130323365353766

Job IDs (Mainnet):

  • Generic _jobId: 0x3164373263663431396562393461663562316636383965303030303732373961
  • AvgTemp _jobId: 0x3438393765336333666531323463336538386464313432643833656231323339
  • TotalRain _jobId: 0x3166313063383862363462663433303362343464373165396534623135396534
  • Hail _jobId: 0x3036636565366230303934393433306262653963333963646536343064386135

Dynamic Request params:

  • _from: 2021-04-01
  • _to: 2021-05-01
  • (Point) _geoJson: { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ 5.325622558593749, 60.3887552979679 ] } } ] }
  • (Polygon) _geoJson: { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [ [ 5.2796173095703125, 60.40673218057448 ], [ 5.164947509765625, 60.383665698324926 ], [ 5.17730712890625, 60.211509994185604 ], [ 5.401153564453124, 60.27694067255946 ], [ 5.6188201904296875, 60.436558668419984 ], [ 5.526123046875, 60.42842688461354 ], [ 5.3002166748046875, 60.5387098888639 ], [ 5.238418579101562, 60.4951151199491 ], [ 5.2796173095703125, 60.40673218057448 ] ] ] } } ] }
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"initiators": [
{
"type": "RunLog",
"params": { "address": "0x292D4Cc76c00D9682230fC712F6B1419eF88aC9b" }
}
],
"tasks": [
{
"type": "google-weather"
},
{
"type": "Multiply"
},
{ "type": "EthUint256" },
{ "type": "EthTx" }
]
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.6/ChainlinkClient.sol";
contract Weather is ChainlinkClient {
using Chainlink for Chainlink.Request;
uint256 public fee;
event AvgTemp(uint256 _result);
event TotalRain(uint256 _result);
event Hail(uint256 _result);
event ResultGeneric(uint256 _result);
constructor(
address _link,
address _oracle,
uint256 _fee
) public {
setChainlinkToken(_link);
setChainlinkOracle(_oracle);
fee = _fee;
}
function requestGeneric(
string memory _geoJson,
string memory _from,
string memory _to,
string memory _method,
string memory _column,
uint256 _times,
bytes32 _jobId
) external {
Chainlink.Request memory req = buildChainlinkRequest(
_jobId,
address(this),
this.fulfillGeneric.selector
);
req.add("geoJson", _geoJson);
req.add("dateFrom", _from);
req.add("dateTo", _to);
req.add("method", _method);
req.add("column", _column);
req.addUint("times", _times);
req.add("units", "metric");
sendChainlinkRequest(req, fee);
}
function fulfillGeneric(
bytes32 _requestId,
uint256 _result
) external recordChainlinkFulfillment(_requestId) {
emit ResultGeneric(_result);
}
function requestAvgTemp(
string memory _from,
string memory _to,
bytes32 _jobId
) external {
Chainlink.Request memory req = buildChainlinkRequest(
_jobId,
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) {
emit AvgTemp(_result);
}
function requestTotalRain(
string memory _from,
string memory _to,
bytes32 _jobId
) external {
Chainlink.Request memory req = buildChainlinkRequest(
_jobId,
address(this),
this.fulfillTotalRain.selector
);
req.add("dateFrom", _from);
req.add("dateTo", _to);
req.add("method", "SUM");
req.add("column", "prcp");
req.add("units", "metric");
sendChainlinkRequest(req, fee);
}
function fulfillTotalRain(
bytes32 _requestId,
uint256 _result
) external recordChainlinkFulfillment(_requestId) {
emit TotalRain(_result);
}
function requestHail(
string memory _from,
string memory _to,
bytes32 _jobId
) external {
Chainlink.Request memory req = buildChainlinkRequest(
_jobId,
address(this),
this.fulfillHail.selector
);
req.add("dateFrom", _from);
req.add("dateTo", _to);
req.add("method", "SUM");
req.add("column", "hail");
req.add("units", "metric");
sendChainlinkRequest(req, fee);
}
function fulfillHail(
bytes32 _requestId,
uint256 _result
) external recordChainlinkFulfillment(_requestId) {
emit Hail(_result);
}
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment