♈
Bootcamp-2024
  • Intro
  • 1. Blockchain & Wallet Fundamentals
    • Blockchain Introduction
    • State Machines
    • Cryptography
    • Distributed Networks
    • Game Theory
    • What is Web3
    • MetaMask Wallet Installation
    • Transferring Tokens with MetaMask
  • 2. Smart Contract & Solidity Fundamentals
    • Using Remix
    • Create, compile and publish your first smart contract
    • Interact with already published smart contracts
    • Blockchain Explorer
    • Verify source code on Etherscan
  • 3. Oracles, ERC20 & Chainlink Data Feeds
    • Oracles
    • Create & Deploy ERC20
    • Data Feeds
  • 4. Cross-Chain Tokens With Chainlink CCIP
    • Setting up MetaMask
    • Getting USDC Testnet Tokens
    • Create Smart Contract In Remix
    • Compile and Deploy
    • Approve USDC
    • Send LINK to your Contract
    • Send USDC from Fuji to Sepolia
    • USDC on Sepolia
  • 5. Mentoring Session
  • 6. NFTs & Chainlink Automation
    • NFT Basics
    • Dynamic NFTs
    • Creating an NFT Smart Contract
    • Deploying Your Dynamic NFTs
  • 7. Chainlink CCIP & Cross-Chain NFT dApps
    • Create and deploy CCIP NFT Contracts
    • Mint on Source Chain
    • Fund Contract
    • Mint On Sepolia From Fuji
    • Mint from Destination 2 - Base Sepolia
  • 8. Random Numbers with Chainlink VRF
    • Introduction to Chainlink VRF
    • Hands On Game Using VRF
  • 9. Off-Chain Data with Chainlink Functions
    • Chainlink Functions Playground
    • Setting up MetaMask
    • Remix
    • Functions Subscription
    • Creating The Functions Consumer Contract
    • Sending a Request from Remix
    • City Weather and Examples
    • City Weather on Chainlink Functions
  • 10. Connecting the 🌏 with Chainlink
  • Glossary
Powered by GitBook
On this page
  1. 9. Off-Chain Data with Chainlink Functions

City Weather and Examples

PreviousSending a Request from RemixNextCity Weather on Chainlink Functions

Last updated 1 year ago

Chainlink Functions Playground

First, go to 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 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:

Try your city or your next vacation spot!

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

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:

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

Chainlink Functions
Chainlink Functions Service Limits
Chainlink Functions Playground - City Weather
https://wttr.in/${city}?format=3&m
The expected output
You get the expected weather back!
Time to add a consumer
Paste in your consumer address and add the consumer
Confirm the transaction
Successfully added another consumer to your subscription