The GetWeather.js
script fetches weather data from the OpenWeather API and maps the API's weather condition ID (weather_id
) to the Weather
enum defined in the smart contract. The script first categorizes weather conditions by calculating weather_id_x
(dividing weather_id
by 100, e.g., 2xx for Thunderstorm, 5xx for Rain).
However, the if-else if
structure only explicitly handles weather_id_x
values for 2 (Thunderstorm), 3 (Drizzle), 5 (Rain), 6 (Snow), and 8 (Clouds/Clear). The OpenWeather API defines other weather ID categories, notably:
7xx (Atmosphere): Includes conditions like Fog, Sand, Dust, Volcanic Ash, Tornado, etc.
According to the current script logic, any weather_id_x
not equal to 2, 3, 5, 6, or 8 (e.g., when weather_id_x
is 7) falls into the final else
clause, causing weather_enum
to be set to 4 (WINDY). This means various non-windy atmospheric conditions (like fog, haze, dust storms) will be incorrectly represented as "WINDY".
The README file acknowledges this as a known issue: "The calculation of weather_enum in GetWeather.js is limited and set to windy in else statement even though multiple weather exists (this is done just to keep limited images)". While this was an intentional choice for image simplicity, it still constitutes an issue from an accuracy and user expectation standpoint, as it leads to the NFT displaying a state incongruent with the actual weather.
Likelihood: High
The OpenWeather API defines various weather condition IDs under the 7xx (Atmosphere) category, which can occur globally.
Whenever these 7xx conditions occur, the script will inaccurately map them to "WINDY".
Impact: Medium
Inaccurate NFT State: The NFT will display a "WINDY" state when the actual weather might be fog, haze, dust storms, tornadoes, etc., which contradicts the NFT's core value proposition of reflecting real weather.
User Confusion and Reduced Trust: Users may notice discrepancies between the NFT's displayed weather and the actual observed weather, eroding trust in the accuracy of the NFT system.
Potential Misjudgment of Value: If the NFT's value or utility is in any way tied to its displayed weather state, inaccurate representation could lead to misjudgments.
A user mints a Weather NFT for a location (e.g., San Francisco).
The actual weather at the location is dense fog, and the OpenWeather API returns a weather ID like 741 (Fog).
The GetWeather.js
script executes:
weather_id
= 741
weather_id_x
= parseInt(741 / 100)
= 7
In the if-else if
conditional logic:
weather_id_x === 2
(false)
weather_id_x === 3 || weather_id_x === 5
(false)
weather_id_x === 6
(false)
weather_id === 800
(false)
weather_id_x === 8
(false)
The else
branch is executed, and weather_enum
is set to 4 (WINDY).
Functions.encodeUint256(4)
is returned to the smart contract.
The smart contract updates the NFT's weather state to WINDY
.
The user views the NFT and sees "WINDY", while it's actually foggy outside, leading to confusion.
Although the README mentions this is for image simplicity, for functionality and accuracy, a more comprehensive handling of weather conditions should be considered, or at least a more neutral or "unknown" default for unhandled categories, rather than misclassifying as "WINDY".
Expand Mapping: Add handling for the 7xx (Atmosphere) category. If the Weather
enum in the contract and image resources allow, map it to a new enum value (e.g., FOGGY_MISTY
) or the closest existing one (e.g., CLOUDY
might be a better approximation for some 7xx conditions than WINDY
if the contract supports it).
More Appropriate Default: If not expanding the enum, change the default value in the else
clause to a more generic state like CLOUDY
(1) or SUNNY
(0), or, if the contract could support it, an UNKNOWN
or OTHER
state. Defaulting unknown or unhandled weather to "WINDY" is misleading.
Update Contract Enum and Images: The most complete solution would be to extend the Weather
enum in the contract to include more weather types (like FOGGY
, HAZY
, etc.) and provide corresponding image URIs.
Given the current fixed Weather
enum in the contract, a pragmatic short-term fix could be to map unhandled cases to CLOUDY
, as this is generally more neutral than WINDY
, or to specifically add a mapping for 7xx (perhaps also to CLOUDY
or another existing state if deemed appropriate by the project).
An example of improved mapping logic in GetWeather.js
, mapping 7xx to CLOUDY
and making the final else
also CLOUDY
as a safer default:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.