City Weather and Examples

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:

The expected output

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:

You get the expected weather back!

Try your city or your next vacation spot!

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

You can have multiple consumer contracts in a single Chainlink Functions Subscription (up to 100)

Chainlink Functions Service Limits

Time to add a consumer

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

Paste in your consumer address and add the consumer

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

Confirm the transaction

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

Successfully added another consumer to your subscription

Last updated