npm run simulate for js source code using @chainlink/functions-toolkit

After running command: npm simulate run, I get the following error:

simulate
node ./Functions-simulate-script.js

secp256k1 unavailable, reverting to browser version
undefined
syntax error, RAM exceeded, or other error
error: Module not found “file:///tmp/FunctionsScript-1715359176579.ts”.

My code is:

swa-func.js

tconst { ethers } = await import('npm:[email protected]');

const abiCoder = ethers.AbiCoder.defaultAbiCoder();

const characterId = args[0];

const url = `https://swapi.dev/api/people/${characterId}/`;

const req = Functions.makeHttpRequest({
    url,
})

const res = await req;


if (res.error) {
    console.log(res.error);
    throw Error("Request failed");
}


console.log("res data available")

console.log("response", res.data)

const character = res.data.name;
const height = res.data.height;

console.log(characterId)
console.log(character)
console.log(height)

const encoded = abiCoder.encode([`string`, `string`, `string`], [characterId, character, height]);

return ethers.getBytes(encoded);
// return Functions.encodeString(`${character} ${height}`);

Functions-request-config.js

const fs = require("fs")
// const { Location, ReturnType, CodeLanguage } = require("@chainlink/functions-toolkit")

// Loads environment variables from .env.enc file (if it exists)
require("@chainlink/env-enc").config()

const Location = {
    Inline: 0,
    Remote: 1,
}

const CodeLanguage = {
    JavaScript: 0,
}

const ReturnType = {
    uint: "uint256",
    uint256: "uint256",
    int: "int256",
    int256: "int256",
    string: "string",
    bytes: "Buffer",
    Buffer: "Buffer",
}

// Configure the request by setting the fields below
const requestConfig = {
    // String containing the source code to be executed
    source: fs.readFileSync("./swa-func.js").toString(),
    //source: fs.readFileSync("./API-request-example.js").toString(),
    // Location of source code (only Inline is currently supported)
    codeLocation: Location.Inline,
    // Optional. Secrets can be accessed within the source code with `secrets.varName` (ie: secrets.apiKey). The secrets object can only contain string values.
    secrets: {},
    // Optional if secrets are expected in the sourceLocation of secrets (only Remote or DONHosted is supported)
    //   secretsLocation: Location.DONHosted,
    // Args (string only array) can be accessed within the source code with `args[index]` (ie: args[0]).
    args: ["2"],
    // Code language (only JavaScript is currently supported)
    codeLanguage: CodeLanguage.JavaScript,
    // Expected type of the returned value
    expectedReturnType: ReturnType.bytes,
    // expectedReturnType: ReturnType.string,
    // Redundant URLs which point to encrypted off-chain secrets
    secretsURLs: [],
}

module.exports = requestConfig

Function-simulate-script.js

const { simulateScript } = require("@chainlink/functions-toolkit");
const requestConfig = require('./Functions-request-config');

async function main() {
    const { responseBytesHexstring, capturedTerminalOutput, errorString } = await simulateScript(requestConfig);

    console.log(responseBytesHexstring);
    console.log(errorString)
    console.log(capturedTerminalOutput);
}

// node Functions-simulate-script.js
main();

package.json

{
  "scripts": {
    "simulate": "node ./Functions-simulate-script.js"
  },
  "dependencies": {
    "@chainlink/env-enc": "^1.0.5",
    "@chainlink/functions-toolkit": "^0.2.8",
    "secp256k1": "^5.0.0"
  }
}

How do I get it to work with chainlink functions toolkit @chainlink. It works fine when I run node swa-example.js
const characterId = “2”;

async function main() {
const url = https://swapi.dev/api/people/${characterId}/;
const res = await fetch(url);
const json = await res.json();
console.log(json);
}

main()

New contributor

thoroughProgrammer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật