To complete Phase 1 of the workshop, you will need to have MetaMask or a similar wallet installed in your browser. You must also have testnet LINK tokens as well as funds to cover transaction gas costs. You can aquire testnet LINK and gas funds at https://faucets.chain.link/
You can follow this tutorial on all testnet chains which Functions currently supports:
Ethereum Sepolia, Polygon Mumbai, Avalanche Fuji, or Arbitrum Sepolia
- Open the Remix editor at https://remix.ethereum.org/ and create a new blank workspace
- Load the
/contract/FunctionsConsumer.solSolidity contract into Remix using the Github URLhttps://github.com/KuphJr/functions-workshop/blob/main/contracts/FunctionsConsumer.sol - Compile & deploy the contract to a testnet blockchain that Functions supports, providing the Functions router contract address and DON ID hex string for the given blockchain which can be found here
- Create a Chainlink Functions subscription at https://functions.chain.link/, add the Functions consumer contract address, and fund the subscription with LINK.
- Set the subscription ID via Remix using
setSubscriptionId - Set the JavaScript code string for the Functions request using
setJavascriptCodeusing code from this Functions Playground example - Send a Functions request using
sendRequestand providing a city in the request arguments array (ex:["New-York"]) - View the Functions request status from the Functions subscription page to see when it is fulfilled
- View the request response (or error) stored in your contract with Remix using
s_lastResponse(ors_lastError) - Decode the response bytes hex string using a hex decoder tool such as this
For Pase 2, you must have Node.js installed. Additionally, you can also install Deno for local simulation (optional).
You also must aquire an RPC URL for your desired blockchain from www.infura.io (or similar) and a soccer free trial API token from sportsdata.io.
- Copy the JavaScript file
/encryptAndUploadSecrets.jsto a file on your local machine - In the same directory as the JavaScript file, run
npm install ethers@5.7.2andnpm install @chainlink/functions-toolkit - Modify
encryptAndUploadSecrets.jsfor your given network as described by the code comments - Set the
PRIVATE_KEYenvironment variable to the private key you used to create your Functions subscription, theAPI_KEYenvironment variable to your API key, and theRPC_URLenvironment variable to your RPC URL - Run the script file with Node.js by running
node /path/to/your/file/encryptAndUpload.js - Set the resulting encrypted secrets hex string in your smart contract via Remix using
setEncryptedSecretsReference - Set the JavaScript code using code from this Functions Playground example using
setJavaScriptCode - Send the request using the arguments (ex:
["2023-01-28", "VEN/GUA"]) and observe the results similar to Phase 1 - (Optional) The Functions Playground runs in your browser and does not perfectly represent the actual Functions execution environment used for on-chain requests. To simulate the source code on your local machine for better debugging, see the file
/simulateScript.js(this requires Deno to be installed)