starknet-io / starknet.js

JavaScript library for StarkNet
https://www.starknetjs.com
MIT License
1.21k stars 706 forks source link

LibraryError: RPC: Invalid params: {"reason":"missing field `simulation_flags`} #1155

Closed egeaybars123 closed 3 weeks ago

egeaybars123 commented 3 weeks ago

Describe the bug I try to use Starknet-js using Javascript on Visual Studio code. I want to set a number in my contract using Invoke, but I keep getting the error:

file:///Users/egeaybars123/Desktop/simple_storage_sdk/node_modules/starknet/dist/index.mjs:2655 throw new LibraryError( ^

LibraryError: RPC: starknet_estimateFee with params {"request":[{"type":"INVOKE","sender_address":"0x067981c7f9f55bcbdd4e0d0a9c5bbcea77dacb42cccbf13554a847d6353f728e","calldata":["0x1","0x1bb7d67375782ab08178b444dbda2b0c1c9ff4469c421124f54e1d8257f2e97","0x2f67e6aeaad1ab7487a680eb9d3363a597afa7a3de33fa9bf3ae6edcb88435d","0x1","0xf"],"version":"0x100000000000000000000000000000001","signature":["0xba4f9aad4ef7d012d58efa81c692aa83decaa13c460fe0b31ca9aa2087783c","0x2c53f24b46bf782bfc07de0b453f407634be319a381ecbf2218bd1a4c31652d"],"nonce":"0x6","max_fee":"0x0"}],"block_id":"pending"}
 -32602: Invalid params: {"reason":"missing field `simulation_flags` at line 1 column 532"}
    at RpcProvider.errorHandler (file:///Users/egeaybars123/Desktop/simple_storage_sdk/node_modules/starknet/dist/index.mjs:2655:13)
    at RpcProvider.fetchEndpoint (file:///Users/egeaybars123/Desktop/simple_storage_sdk/node_modules/starknet/dist/index.mjs:2671:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Account.estimateInvokeFee (file:///Users/egeaybars123/Desktop/simple_storage_sdk/node_modules/starknet/dist/index.mjs:4338:22)
    at async Account.getSuggestedMaxFee (file:///Users/egeaybars123/Desktop/simple_storage_sdk/node_modules/starknet/dist/index.mjs:4637:23)
    at async Account.execute (file:///Users/egeaybars123/Desktop/simple_storage_sdk/node_modules/starknet/dist/index.mjs:4446:49)
    at async file:///Users/egeaybars123/Desktop/simple_storage_sdk/index.js:29:13

To Reproduce You can copy and paste my code to reproduce the problem:


import { Account, RpcProvider, json, Contract } from 'starknet';
import fs from 'fs';
import * as dotenv from 'dotenv';
dotenv.config();

const privateKey = process.env.PRIVATE_KEY;
const ApiKey = process.env.API_KEY;
//https://starknet-sepolia.public.blastapi.io
const provider = new RpcProvider({ nodeUrl: 'https://starknet-sepolia.g.alchemy.com/v2/' + ApiKey });

const accountAddress = '0x067981c7F9f55BCbdD4e0d0a9C5BBCeA77dAcB42cccbf13554A847d6353F728e';

const account = new Account(provider, accountAddress, privateKey, "1");

const compiledContractAbi = json.parse(
    fs.readFileSync('./abi.json').toString('ascii')
);

const contractAddress = '0x01bb7d67375782ab08178b444dbda2b0c1c9ff4469c421124f54e1d8257f2e97';
const storageContract = new Contract(compiledContractAbi.abi, contractAddress, provider);

storageContract.connect(account);

const getData = await storageContract.get();
console.log('Stored_data before set():', getData.toString());

const myCall = storageContract.populate('set', [15]);
const res = await storageContract.set(myCall.calldata);
await provider.waitForTransaction(res.transaction_hash);

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

egeaybars123 commented 3 weeks ago

I fixed the problem. I was following along the Starknet-js documentation, and I found out that I needed to change the version to "Next" in the documentation. Then, I found out that rpc version was v0.6, so I bumped the Starknet-js version to 6.6.6. Then, the problem was fixed, and I could invoke a function in my contract.