NEW

Chainlink Data Streams have officially launched on mainnet. Sign up for early access.

Back

Simulate your Functions

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:

To explore the capabilities of Chainlink Functions, visit the Chainlink Functions 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.

This repository comes preconfigured with Hardhat and the Chainlink Functions Toolkit NPM package, allowing you to quickly get started with Functions.

To simulate:

  1. In a terminal, clone the functions-hardhat-starter-kit repository and change to the functions-hardhat-starter-kit directory.

    git clone https://github.com/smartcontractkit/functions-hardhat-starter-kit && \
    cd functions-hardhat-starter-kit
  2. Run npm install to install the dependencies.

    npm install
  3. For simulation, you don't need to set up the environment variables. Run npx hardhat functions-simulate-script to simulate the calculation-example.js JavaScript source code.

    npx hardhat functions-simulate-script

    Result:

    secp256k1 unavailable, reverting to browser version
    
    
    Response returned by script during local simulation: 1003757

Follow the Simple Computation guide to learn how to import the Chainlink Functions Toolkit NPM package into your JavaScript project to simulate and execute a Functions request. You can read the Examine the code section for a detailed description of the code example.

Stay updated on the latest Chainlink news