0

Hello Im a bit confused about this error and what im doing wrong, here is my code

const { Connection, clusterApiUrl } = require('@solana/web3.js');


const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed');
//below is for getblock
GetBlockConfig: {
  commitment: 'finalized';
  rewards: false;
  transactionDetails: "full";
}

//below is for get transactions
GetVersionedBlockConfig: {
  commitment: 'finalized';
  maxSupportedTransactionVersion: 0;
  rewards: false;
  transactionDetails: "full";
}


async function fetchCurrentSlot() {
  const currentSlot = await connection.getSlot();
  console.log('Current slot:', currentSlot);
  return currentSlot;
}

async function fetchBlock() {
  try {
      const currentSlot = await fetchCurrentSlot();
      const block = await connection.getBlock(currentSlot, GetBlockConfig);
      console.log(block);
  } catch (error) {
      console.error("Error fetching block:", error);
  }
}

fetchBlock();

and this is the error im getting

Current slot: 265806271
Error fetching block: ReferenceError: GetBlockConfig is not defined
    at fetchBlock (C:\Users\user\OneDrive\Desktop\Solana sniper\solana.js:30:60)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Im confused as to why its not defined, the formatting seems to be right comparing it to the docs so im not sure. I would appreciate some help on this.

Thanks and have a nice day!

1 Answer 1

1

This looks like a syntax error in JavaScript. Try defining the object separately as:

const GetBlockConfig = {
  commitment: 'finalized',
  maxSupportedTransactionVersion: 0,
  rewards: false,
  transactionDetails: "full",
};

You can see how this is being used in some of the tests, like at: https://github.com/solana-labs/solana-web3.js/blob/26dae190c2ec835fbdaa7b7d66ca33d6ba0727b8/packages/library-legacy/test/connection.test.ts#L6126

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.