Hedging Against Bad Weather with Cloud Datasets and Blockchain Oracles

Allen Day
Allen Day
Aug 6 · 8 min read

In this article, we demonstrate how open weather data and blockchain technology, combined with capabilities from Google Cloud, can create economic efficiencies and through sustainable agriculture mitigate climate change.

Unexpected adverse weather events lead to economic losses across a wide range of industries, and these events are becoming more common as we experience climate change. Examples include reduced crop yields during drought, disrupted travel itineraries during snowstorms, cancelled sports events during excessive rainfall, and existential risks and infrastructure failures caused by large-magnitude bad weather.

While we don’t yet have the technology to control the weather, the impact of adverse weather events can be mitigated when the events themselves are more predictable. Fortunately, more accurate forecasts can be made when more data is available. Google Cloud’s Public Datasets Program hosts petabytes of useful datasets, such as historical weather and climate data, that businesses can instantly access to optimize analytic models around weather risk and create data-driven solutions. And this is already happening; machine learning algorithms that are used for weather forecasting are being used to create financial products like weather insurance.

Making weather data directly available to the financial markets is another promising avenue to mitigate weather-related losses and introduces an opportunity to improve forecasts themselves, as the market-makers with more accurate weather models will outperform in weather prediction capital markets.

I previously described the hybrid blockchain/cloud application software design pattern, and in this blog post, we’ll focus specifically on how to realize the pattern by making high-quality weather data available to the emerging Decentralized Finance (DeFi) capital markets. Because these markets are open to all participants with an internet connection (permissionless) and can operate on well-defined and structured data, they present an opportunity to bring weather data-driven financial products to the market instantly and at global scale.

However as potential impact increases, so does potential risk. As enterprises begin to incorporate smart contracts — trust-minimized digital agreements on blockchain networks — into their business processes, it is imperative that the data driving these contracts is of high quality and is securely and reliably delivered. Fortunately, these challenges can be overcome, as we’ll describe.

Regarding data quality, Google Cloud hosts in BigQuery the Global Surface Summary of the Day (GSOD) database from the National Oceanic and Atmospheric Administration (NOAA). In brief, GSOD provides daily summaries of weather and climate observations from more than 9000 globally distributed stations going back to 1929. Weather and climate data is sourced from reputable data providers including the GPM program, a joint venture between the National Aeronautics and Space Administration (NASA) and the Japan Aerospace Exploration Agency (JAXA) that provides global mapping of precipitation at three hour intervals based on multi-satellite retrievals.

In the next section, we’ll take a look at how a solution can be built to deliver weather data from Google BigQuery, via Chainlink (a blockchain oracle solution that secures $30B+ for smart contract ecosystems), to Ethereum, the smart contract platform which hosts the largest DeFi markets. Then to wrap up, we’ll talk about how and why these data might best be applied to develop sustainable agriculture practices.

Connecting Google Cloud’s Weather and Climate Datasets to Smart Contracts With Chainlink

Blockchain-based smart contract applications provide key advantages for businesses by mitigating counterparty risk, expediting settlement, and reducing the friction of entering into financial agreements. With weather data (e.g. rainfall) as an input, smart contracts can further enable prediction markets in which participants might agree to terms like:

For <price>, we’ll agree to a future transfer to the buyer of <amount> at <settlement time> if <weather measurement> at <geographical location> is <greater or less> than <amount> during <time range>.

Such agreements allow businesses to hedge against extreme weather fluctuations in temperature, wind speed, precipitation, and other conditions. Such hedging impacts the profitability — and in some cases viability — of specific industries.

But “on-chain” smart contracts cannot natively access external “off-chain” inputs about weather. This is a security feature of blockchains, and means that a bridging component, known as a blockchain oracle, is needed to build hybrid blockchain/cloud applications.

I worked with the Chainlink engineers to build an adapter that enables smart contracts to query the NOAA GSOD weather data via BigQuery. GSOD provides daily measurements from more than 9000 weather stations, including each location’s temperature, visibility, wind speed, precipitation, and more.

The adapter accepts weather data requests from smart contracts on any of the 50+ platforms that Chainlink supports. It translates on-chain function calls from third-party applications into the correct form to retrieve the GSOD data hosted in BigQuery, and returns the data for downstream use. The boxes/arrows outlined in red are the components we built for this blog post.

Source code is available on Github and you can interact with the GSOD data on the Ethereum Goerli testnet at address 0x6B705Fc5c425bE07EBe59d09aA9fD2C0Df88CAb4 and the Ethereum Mainnet at address 0x7F7D84789eAfb80A6bA0B996D37A06723FCc02c5.

Application developers can request data from weather stations within a specific region or for the weather station nearest to a specified point.

To showcase our solution, on-chain data request transactions from an Ethereum smart contract were generated on the Goerli Testnet. This contract has several functions that return weather data, and we’ll show some examples of them in detail here.

While these examples are focused on a specific location (Bergen, Norway), the requested location can be specified with a GeoJSON data structure or Geohash for more flexibility.

Example Query 1, fixed location: What was the measured <AVERAGE TEMPERATURE> at Bergen, Norway over the time period <START, END>?

This request transaction showcases the requestAvgTemp() function being called by a smart contract to request the average temperature in Bergen, Norway between April 1st to May 1st 2021 using the Chainlink node’s pre-configured job. The input dates given by the requester can be viewed on the Etherscan page by clicking Decode Input Data. After the geo-coordinates, time span, aggregation method, weather type, and units defined in the request transaction are received by the off-chain Chainlink node, the following input is provided to the node’s external adapter:

After being received by the external adapter, the following output of 5.29º C is produced before generating an on-chain response transaction with the value encoded as uint256 and multiplied by 10^18 for decimal support using the Chainlink node’s pipeline:

After receiving this real-world weather data, consuming smart contracts can leverage this data to execute application-specific logic.

Example Query 2, fixed location: What was the measured <TOTAL RAINFALL> at Bergen, Norway over the time period <START, END>?

In addition to fetching the daily average temperature in Bergen, Norway, this Chainlink node and external adapter combo can also be used to fetch other weather datasets such as the total rainfall from Bergen, Norway using a pre-configured job. This request transaction showcases the requestTotalRain() function being called by a smart contract to request the total rainfall in Bergen, Norway between April 1st to May 1st 2021 using a predefined geo-coordinate. The only input given by the requesting smart contract is the timeframe the data should reference. In processing this data request, the Chainlink node’s external adapter is given the following input payload:

After fetching the data off-chain through Google BigQuery, the Chainlink node’s external adapter provides the following result, indicating the number of millimeters of rain within the predefined geographic region on the given timeframe, which is then delivered on-chain through on-chain response transaction, returning the result encoded in uint256 and multiplied by 10^18 to provide decimal support:

Example Query 3, fixed location: What was the measured <TOTAL HAIL> at Bergen, Norway over the time period <START, END>?

The third example job provided by the Chainlink node allows smart contracts to query if there was hail in a coordinate range covering Bergen, Norway within a given date range by calling the requestHail() function. Like the previous job, the only input given by the requesting smart contract is the time period to be queried as shown in this request transaction. A time period without hail returns zero, while any other numerical value indicates hail occurred for a specific number of days within that range. In processing the hail occurrence data request, the Chainlink node’s external adapter is given the following input payload:

After receiving the given payload, the Chainlink node’s external adapter fetches the weather data from BigQuery and provides the following output showcasing the number of days where the occurrence of hail occurred, which is then delivered on-chain through a response transaction:

As the result is greater than zero, this result shows that there was at least one day of hail within the predefined geographic region. By using this Chainlink node, smart contracts that require external weather data can request data from any geographic region in the world where one or multiple weather stations reside.

Powering next-generation crop insurance with smart contracts

With NOAA weather and climate data hosted on Google Cloud now accessible directly on-chain through Chainlink, smart contract developers can create preprogrammed crop insurance agreements that automatically and reliably settle claims based on high-quality real-world data.

As markets for such agreements emerge, businesses gain the ability to hedge risk, regardless of their size, jurisdiction, or location, allowing them to plan and safely expand their operations knowing they are fully covered against adverse weather events. These products encourage more sustainable agriculture and have a stabilizing effect on land-use change, a major contributor to carbon dioxide emissions.

Similarly, by building agreements based on smart contracts, underwriters and policyholders alike have greater guarantees that the settlement of claims occurs based on data that accurately reflects real-world conditions, introducing an unprecedented level of transparency, reliability, and permissionless access to the crop insurance industry.

Further, because they’re built with public smart contracts, weather coverage can be provided globally and at micro-scale without the downsides and inefficiencies that affect traditional insurance settlements such as delayed payments and subjective adjustments.

Redefining global industries with hybrid blockchain/cloud applications

The demand for high-quality off-chain data in the smart contract ecosystem continues to grow at a rapid pace and must be matched with industry-redefining tools that allow smart contract developers to build the innovative applications and use cases they envision. With NOAA weather data made available on-chain by Google Cloud and Chainlink, decentralized and permissionless applications such as smart contract crop insurance agreements can be created to provide previously inaccessible risk management products.

Hybrid blockchain/cloud applications have the ability to redefine the financial economy and we are more than excited to see what additional smart contract applications are created as a result. Smart contract crop insurance has the potential to improve quality of service and execution guarantees, thereby increasing the accessibility of financial services. We anticipate that by following the pattern outlined within this article, a number of other applications can be built with Chainlink and the wide variety of public data available on GCP.

We look forward to seeing the innovative smart contract applications that developers and businesses create by combining Google Cloud Platform and Chainlink oracle middleware.

Learn more

Google Cloud - Community

Google Cloud community articles and blogs

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Allen Day

Written by

Allen Day

Google Cloud - Community

A collection of technical articles and blogs published or curated by Google Cloud Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.