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 2c1adcf5380..0beb9a11e54 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..085c53fc7a5 --- /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 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. + + + +## 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. 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 + ``` + + 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 184d3b595bb..00f3a96c4ce 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 } ] }