1.0.22 • Published 5 months ago
jsaccountactivitysdk v1.0.22
JSAccountActivitySDK
A JavaScript SDK for tracking and classifying account activity on the Aptos blockchain. This SDK provides utilities to fetch and classify transactions, making it easy to track deposits, withdrawals, and swaps.
Installation
npm install jsaccountactivitysdk
Usage
Complete Example with Real Data
Here's a complete example showing how to fetch and process real transaction data:
const { AptosGraphQLClient } = require('jsaccountactivitysdk');
async function main() {
const client = new AptosGraphQLClient('https://api.mainnet.aptoslabs.com/v1/graphql');
// Example address with various transaction types
const address = '0x54f87920d93bc215c7b70d42a480438cfe01d7b4db259a8184faa8f8e2899be1';
const transactions = await client.getClassifiedTransactions(address);
console.log('Total transactions:', transactions.length);
// Print some example transactions of different types
transactions.forEach(tx => {
console.log(JSON.stringify(tx, null, 2));
});
}
main();
This will output something like:
// First swap transaction - CASH to USDC
{
"type": "swap",
"spendTokens": [
{
"token": "0x61ed8b048636516b4eaf4c74250fa4f9440d9c3e163d96aeb863fe658a4bdc67::CASH::CASH",
"amount": 1000000
}
],
"receiveTokens": [
{
"token": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
"amount": 307
}
],
"intermediaryTokens": [],
"transaction_version": 2278143016,
"gas_amount": "0"
}
// Second swap transaction - Multiple output tokens
{
"type": "swap",
"spendTokens": [
{
"token": "0x159df6b7689437016108a019fd5bef736bac692b6d4a1f10c941f6fbb9a74ca6::oft::CakeOFT",
"amount": 79394602
}
],
"receiveTokens": [
{
"token": "0x1::aptos_coin::AptosCoin",
"amount": 20200000
},
{
"token": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
"amount": 4876
}
],
"intermediaryTokens": [],
"transaction_version": 2251956887,
"gas_amount": "0"
}
// Receive transaction - APT deposit
{
"type": "receive",
"tokens": [
{
"token": "0x1::aptos_coin::AptosCoin",
"amount": 4739309756
}
],
"transaction_version": 2251955282,
"gas_amount": "0"
}
// Send transaction - USDC withdrawal with gas fee
{
"type": "send",
"tokens": [
{
"token": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
"amount": 4238031
}
],
"transaction_version": 2231966471,
"gas_amount": 49300
}
// ... more transactions ...
React Hooks
The SDK also provides React hooks for easy integration with React applications:
import { useClassifiedTransactions } from 'jsaccountactivitysdk';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// In your component:
function TransactionList({ address }) {
const { data, isLoading, error } = useClassifiedTransactions(address);
if (isLoading) return 'Loading...';
if (error) return 'Error: ' + error.message;
return (
<div>
{data.map(tx => (
<div key={tx.transaction_version}>
{/* Render transaction details */}
</div>
))}
</div>
);
}
Transaction Types
The SDK classifies transactions into three main types:
- send - Outgoing transfers
- receive - Incoming transfers
- swap - Token swap transactions
API Reference
AptosGraphQLClient
Constructor
new AptosGraphQLClient(graphql_url, api_key = null)
Methods
getClassifiedTransactions(address)
React Hooks
useClassifiedTransactions(address, client)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT