Query Transactions
wangqi
2024-09-28 23:30
· edited
The listTransactions
query allows you to fetch a list of transactions on the blockchain based on various criteria. This can be useful for monitoring specific types of transactions, analyzing account activity, or tracking asset-related operations.
const Client = require('@ocap/client');
const endpoint = 'https://main.abtnetwork.io/api';
const client = new Client(endpoint);
async function listTransactions(params) {
try {
const result = await client.listTransactions(params);
console.log('Transactions:', result.transactions);
console.log('Pagination:', result.page);
} catch (error) {
console.error('Error listing transactions:', error);
}
}
// Usage examples
(async () => {
// List transactions with pagination
await listTransactions({
paging: { size: 10, cursor: '' }
});
// List transactions by address
await listTransactions({
addressFilter: { sender: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' }
});
// List transactions by time range
await listTransactions({
timeFilter: {
startDateTime: '2023-01-01T00:00:00Z',
endDateTime: '2023-12-31T23:59:59Z'
}
});
// List transactions by type
await listTransactions({
typeFilter: { types: ['transfer'] }
});
// List valid transactions only
await listTransactions({
validityFilter: { validity: 'VALID' }
});
// List transactions related to a specific token
await listTransactions({
tokenFilter: { address: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' }
});
// List transactions related to a specific asset
await listTransactions({
assetFilter: { address: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' }
});
// List transactions with multiple filters
await listTransactions({
addressFilter: { sender: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' },
timeFilter: {
startDateTime: '2023-01-01T00:00:00Z',
endDateTime: '2023-12-31T23:59:59Z'
},
typeFilter: { types: ['transfer'] },
validityFilter: { validity: 'VALID' },
paging: { size: 20, cursor: '' }
});
// List staking-related transactions
await listTransactions({
stakeFilter: { address: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' }
});
// List delegation-related transactions
await listTransactions({
delegationFilter: { address: 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr' }
});
})();
Sticker