Hello I hope you are all having a great day!!
I wanted to ask how I would go about decoding transaction instructions into a readable format. This is my code below
const { decodeMintToInstruction, decodeMintToCheckedInstruction, decodeInstruction } = require('@solana/spl-token');
const { Connection, clusterApiUrl } = require('@solana/web3.js');
const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed');
//below is for getblock https://solana-labs.github.io/solana-web3.js/types/GetBlockConfig.html
GetBlockConfig: {
commitment: 'finalized';
rewards: false;
transactionDetails: "full";
}
//below is for get transactions if i need it later
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 rawConfig = {
encoding: 'json',
maxSupportedTransactionVersion: 0,
}
const block = await connection.getBlock(currentSlot,rawConfig );
console.log(block);
console.log('First transaction details:', JSON.stringify(block.transactions[0].transaction, null, 2));
const transactionData = block.transactions[0].transaction.message.instructions[0].data
const transactionInstructions = block.transactions[0].transaction.message.instructions[0]
//const decodedInstructions = method to decode the instructions when i find one that works
console.log('First transaction instructions data:',transactionData);
//console.log('First transaction instructions decoded', decodedInstructions)
} catch (error) {
console.error("Error fetching block:", error);
}
}
fetchBlock();
I want to be able to decode the transaction information but im not sure how, from what I have seen I need to convert it from base58 to unint8. Can anyone give me an example on how to do this?
Thanks and have a great day!