NEW

Developer Passes are now available for Chainlink SmartCon. Get yours today.

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 use the Chainlink Functions 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. 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 to compute the total amount after interest.

    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