From 21344f4f9cb78cb43c982f3bf5a585d260e57667 Mon Sep 17 00:00:00 2001 From: aelmanaa Date: Tue, 9 Jan 2024 12:45:48 +0100 Subject: [PATCH 1/5] improve simulation guide --- .vscode/settings.json | 1 + src/config/sidebar.ts | 4 +- .../resources/playground.mdx | 12 --- .../resources/simulation.mdx | 78 +++++++++++++++++++ src/features/redirects/redirects.json | 21 +++-- 5 files changed, 94 insertions(+), 22 deletions(-) delete mode 100644 src/content/chainlink-functions/resources/playground.mdx create mode 100644 src/content/chainlink-functions/resources/simulation.mdx diff --git a/.vscode/settings.json b/.vscode/settings.json index 62a41e72ae2..1bf0ac094e8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -40,6 +40,7 @@ "Numberish", "NUON", "preact", + "preconfigured", "quickstarts", "Sepolia", "tbody", diff --git a/src/config/sidebar.ts b/src/config/sidebar.ts index e4014117234..577f5ad5113 100644 --- a/src/config/sidebar.ts +++ b/src/config/sidebar.ts @@ -560,8 +560,8 @@ export const SIDEBAR: Partial> = { url: "chainlink-functions/resources/secrets", }, { - title: "Functions playground", - url: "chainlink-functions/resources/playground", + title: "Simulate your Functions", + url: "chainlink-functions/resources/simulation", }, { title: "Managing Subscriptions", diff --git a/src/content/chainlink-functions/resources/playground.mdx b/src/content/chainlink-functions/resources/playground.mdx deleted file mode 100644 index 3a4c17a8cc2..00000000000 --- a/src/content/chainlink-functions/resources/playground.mdx +++ /dev/null @@ -1,12 +0,0 @@ ---- -section: chainlinkFunctions -date: Last Modified -title: "Chainlink Functions Playground" ---- - -import { ClickToZoom } from "@components" - -To explore the capabilities of Chainlink Functions, visit the [Chainlink Functions Playground](https://functions.chain.link/playground). This playground can simulate Chainlink Functions within the browser, call APIs, and execute demo requests. -To use the playground, enter any source code, arguments, and secrets you would like to use. Click the **Run code** button to view the output. - - diff --git a/src/content/chainlink-functions/resources/simulation.mdx b/src/content/chainlink-functions/resources/simulation.mdx new file mode 100644 index 00000000000..6454e76f13b --- /dev/null +++ b/src/content/chainlink-functions/resources/simulation.mdx @@ -0,0 +1,78 @@ +--- +section: chainlinkFunctions +date: Last Modified +title: "Simulate your Functions" +--- + +import { ClickToZoom, Aside } from "@components" + +Before making a Chainlink Functions request from your smart contract, it is always a good practice to simulate the source code off-chain to make any adjustments or corrections. + +Currently, there are several options for simulating a request: + +- [Chainlink Functions playground](https://functions.chain.link/playground). + +- [Chainlink Functions Hardhat Starter Kit](https://github.com/smartcontractkit/functions-hardhat-starter-kit): Use the `npx hardhat functions-simulate-script` command to simulate your Functions JavaScript source code. + +- [Chainlink Functions Toolkit NPM package](https://github.com/smartcontractkit/functions-toolkit): Import this NPM package into your JavaScript/TypeScript project, then use the `simulateScript` function to simulate your Functions JavaScript source code. + +## Chainlink Functions playground + + + +To explore the capabilities of Chainlink Functions, visit the [Chainlink Functions Playground](https://functions.chain.link/playground). This playground can simulate Chainlink Functions within the browser, call APIs, and execute demo requests. +To use the playground, enter any source code, arguments, and secrets you would like to use. Click the **Run code** button to view the output. + + + +## Chainlink Functions Hardhat Starter Kit + +This repository comes preconfigured with [Hardhat](https://hardhat.org/) and the [Chainlink Functions Toolkit NPM package](https://github.com/smartcontractkit/functions-toolkit), allowing you to quickly get started with Functions. + +To simulate: + +1. In a terminal, clone the [functions-hardhat-starter-kit repository](https://github.com/smartcontractkit/functions-hardhat-starter-kit) and change to the `functions-hardhat-starter-kit` directory. + + ```shell + git clone https://github.com/smartcontractkit/functions-hardhat-starter-kit && \ + cd functions-hardhat-starter-kit + ``` + +1. Run `npm install` to install the dependencies. + + ```shell + npm install + ``` + +1. For simulation, you don't need to set up the environment variables. Go ahead and run `npx hardhat functions-simulate-script` to simulate the [calculation-example.js](https://github.com/smartcontractkit/functions-hardhat-starter-kit/blob/main/calculation-example.js) JavaScript source code. + + ```shell + npx hardhat functions-simulate-script + ``` + + Result: + + ```text + secp256k1 unavailable, reverting to browser version + + + Response returned by script during local simulation: 1003757 + ``` + + + +## Chainlink Functions Toolkit NPM package + +Follow the [Simple Computation](/chainlink-functions/tutorials/simple-computation) guide to learn how to import the [Chainlink Functions Toolkit NPM package](https://github.com/smartcontractkit/functions-toolkit) into your JavaScript project to simulate and execute a Functions request. +You can read the [Examine the code section](/chainlink-functions/tutorials/simple-computation#javascript-example) for a detailed description of the code example. diff --git a/src/features/redirects/redirects.json b/src/features/redirects/redirects.json index 672609f3be7..f4c5f33885d 100644 --- a/src/features/redirects/redirects.json +++ b/src/features/redirects/redirects.json @@ -1801,42 +1801,42 @@ "statuscode": 301 }, { - "source": "/chainlink-automation/flexible-upkeeps", + "source": "chainlink-automation/flexible-upkeeps", "destination": "chainlink-automation/guides/flexible-upkeeps", "statuscode": 301 }, { - "source": "/chainlink-automation/job-scheduler", + "source": "chainlink-automation/job-scheduler", "destination": "chainlink-automation/guides/job-scheduler", "statuscode": 301 }, { - "source": "/chainlink-automation/manage-upkeeps", + "source": "chainlink-automation/manage-upkeeps", "destination": "chainlink-automation/guides/manage-upkeeps", "statuscode": 301 }, { - "source": "/chainlink-automation/automation-architecture", + "source": "chainlink-automation/automation-architecture", "destination": "chainlink-automation/concepts/automation-architecture", "statuscode": 301 }, { - "source": "/chainlink-automation/automation-concepts", + "source": "chainlink-automation/automation-concepts", "destination": "chainlink-automation/concepts/automation-concepts", "statuscode": 301 }, { - "source": "/chainlink-automation/automation-release-notes", + "source": "chainlink-automation/automation-release-notes", "destination": "chainlink-automation/overview/automation-release-notes", "statuscode": 301 }, { - "source": "/chainlink-automation/getting-started", + "source": "chainlink-automation/getting-started", "destination": "chainlink-automation/overview/getting-started", "statuscode": 301 }, { - "source": "/chainlink-automation/automation-economics", + "source": "chainlink-automation/automation-economics", "destination": "chainlink-automation/overview/automation-economics", "statuscode": 301 }, @@ -1849,6 +1849,11 @@ "source": "ccip/supported-networks/testnet", "destination": "ccip/supported-networks/v1_2_0/testnet", "statuscode": 301 + }, + { + "source": "chainlink-functions/resources/playground", + "destination": "chainlink-functions/resources/simulation", + "statuscode": 301 } ] } From 1d3a9eab19dc1bdda668c62ea3b01f1480a2b9f7 Mon Sep 17 00:00:00 2001 From: Amine E Date: Wed, 10 Jan 2024 08:33:06 +0100 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Crystal Gomes --- src/content/chainlink-functions/resources/simulation.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/chainlink-functions/resources/simulation.mdx b/src/content/chainlink-functions/resources/simulation.mdx index 6454e76f13b..5bfbdabceed 100644 --- a/src/content/chainlink-functions/resources/simulation.mdx +++ b/src/content/chainlink-functions/resources/simulation.mdx @@ -20,8 +20,8 @@ Currently, there are several options for simulating a request: @@ -50,7 +50,7 @@ To simulate: npm install ``` -1. For simulation, you don't need to set up the environment variables. Go ahead and run `npx hardhat functions-simulate-script` to simulate the [calculation-example.js](https://github.com/smartcontractkit/functions-hardhat-starter-kit/blob/main/calculation-example.js) JavaScript source code. +1. For simulation, you don't need to set up the environment variables. Run `npx hardhat functions-simulate-script` to simulate the [calculation-example.js](https://github.com/smartcontractkit/functions-hardhat-starter-kit/blob/main/calculation-example.js) JavaScript source code. ```shell npx hardhat functions-simulate-script From 9783eca3e6cfb2ddbddb3343ca9411d21d10ea27 Mon Sep 17 00:00:00 2001 From: aelmanaa Date: Wed, 10 Jan 2024 08:44:43 +0100 Subject: [PATCH 3/5] clarifications ' --- .../chainlink-functions/resources/simulation.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/content/chainlink-functions/resources/simulation.mdx b/src/content/chainlink-functions/resources/simulation.mdx index 5bfbdabceed..c81044e9351 100644 --- a/src/content/chainlink-functions/resources/simulation.mdx +++ b/src/content/chainlink-functions/resources/simulation.mdx @@ -19,15 +19,15 @@ Currently, there are several options for simulating a request: ## Chainlink Functions playground -To explore the capabilities of Chainlink Functions, visit the [Chainlink Functions Playground](https://functions.chain.link/playground). This playground can simulate Chainlink Functions within the browser, call APIs, and execute demo requests. -To use the playground, enter any source code, arguments, and secrets you would like to use. Click the **Run code** button to view the output. +To use the [Chainlink Functions +Playground](https://functions.chain.link/playground), enter any source code, arguments, and secrets you would like to use. Click the **Run code** button to view the output. @@ -50,7 +50,7 @@ To simulate: npm install ``` -1. For simulation, you don't need to set up the environment variables. Run `npx hardhat functions-simulate-script` to simulate the [calculation-example.js](https://github.com/smartcontractkit/functions-hardhat-starter-kit/blob/main/calculation-example.js) JavaScript source code. +1. For simulation, you don't need to set up the environment variables. Run `npx hardhat functions-simulate-script` to simulate the [calculation-example.js](https://github.com/smartcontractkit/functions-hardhat-starter-kit/blob/main/calculation-example.js) JavaScript source code. **Note:** This example calculates the continuously compounding interest for a given principal amount over one month. It takes the principal amount and annual percentage yield (APY) as input arguments and uses [Euler's number](https://www.investopedia.com/terms/e/eulers-constant.asp) to compute the total amount after interest. ```shell npx hardhat functions-simulate-script From 822add1b97c1a2cfbf4f393e572bf217152dfab8 Mon Sep 17 00:00:00 2001 From: aelmanaa Date: Wed, 10 Jan 2024 08:48:15 +0100 Subject: [PATCH 4/5] clarifications ' --- .../chainlink-functions/resources/simulation.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/chainlink-functions/resources/simulation.mdx b/src/content/chainlink-functions/resources/simulation.mdx index c81044e9351..9949095b1df 100644 --- a/src/content/chainlink-functions/resources/simulation.mdx +++ b/src/content/chainlink-functions/resources/simulation.mdx @@ -19,11 +19,11 @@ Currently, there are several options for simulating a request: ## Chainlink Functions playground To use the [Chainlink Functions From eba5c35117a63bd5239ee8524612b440cd7fd8df Mon Sep 17 00:00:00 2001 From: aelmanaa Date: Wed, 10 Jan 2024 08:49:56 +0100 Subject: [PATCH 5/5] clarifications --- src/content/chainlink-functions/resources/simulation.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/chainlink-functions/resources/simulation.mdx b/src/content/chainlink-functions/resources/simulation.mdx index 9949095b1df..085c53fc7a5 100644 --- a/src/content/chainlink-functions/resources/simulation.mdx +++ b/src/content/chainlink-functions/resources/simulation.mdx @@ -68,8 +68,8 @@ To simulate: ## Chainlink Functions Toolkit NPM package