City Weather and Examples
Chainlink Functions Playground
First, go to Chainlink Functions Playground - City Weather and the source code will be loaded into the playground. Alternatively, you can copy and paste the following code into a blank playground:
const city = args[0];
const apiResponse = await Functions.makeHttpRequest({
url: `https://wttr.in/${city}?format=3&m`,
responseType: 'text'
});
if (apiResponse.error) {
throw Error('Request failed');
}
const { data } = apiResponse;
return Functions.encodeString(data);
Copy the HTTP request https://wttr.in/${city}?format=3&m and replace city
with Sao-Paulo in a browser to see the expected result:

Back in the playground, 1. make sure the “Argument” is Sao-Paulo
then 2. click the “Run code” blue button at the bottom left and 3. the “Output” will be displayed:

Navigate back to your subscription on Chainlink Functions and click the "Add consumer" button on the far right:

Now 1. paste in your WeatherFunctions.sol
deployed address and then 2. click the “Add consumer” blue button:

MetaMask will pop-up for you to confirm the transaction:

Once the transaction is confirmed, refresh the page and you will now see your new consumer:

Last updated