npm i starknet-account-analyzer
You declare the package with:
- A provider
The package comes with a custom RPC provider (only useful functions have been implemented and follow the behavior of the starknetjs Provider)
- Blocks
This can be an empty object, in this case the class will query the blocks to your provider, but you can also provider already fetched blocks (following a starknetjs block interface) to avoid losing time fetching blocks.
- Time between block queries.
In case you have to fecth blocks, you can chose a sleep time to avoid spamming the provider
import { AccountAnalyzer } from "starknet-account-analyzer/lib/AccountAnalyzer/AccountAnalyzer";
import { RPCProvider } from "./RPCProvider/RPCProvider";
const URL = "http://127.0.0.1:9545";
const provider = new RPCProvider(URL);
const accountAnalyzer = new AccountAnalyzer(provider, {}, 500);
Here is a full example of how you can use the package.
-
Fetch blocks
-
Organize all the activity from any contracts that made or received a transaction within those blocks
-
Filter the most active ACCOUNTS (accounts = a contract called
__execute__
at least once) -
See the returned object with organized transactions
import { AccountAnalyzer } from "starknet-account-analyzer/lib/AccountAnalyzer/AccountAnalyzer";
import { RPCProvider } from "./RPCProvider/RPCProvider";
const URL = "http://127.0.0.1:9545";
const provider = new RPCProvider(URL);
const accountAnalyzer = new AccountAnalyzer(provider, {}, 500);
export const fetchBlocksAndContractsAndAccounts = async function() {
const accountAnalyzer = new AccountAnalyzer(provider, {}, 500);
const [startBlockNumber, latestBlockNumber] = await accountAnalyzer.getYesterdayBlockRange();
const sortedContractsActivity = (
await accountAnalyzer.getTopAccountsFromBlockNumbers(startBlockNumber, latestBlockNumber)
).sortedContractsActivity;
const organizedAccountsActivity = (
await accountAnalyzer.organizeTransactionsForAccounts(15, sortedContractsActivity)
).organizedAccountsActivity;
return {
blocks: accountAnalyzer.blocks,
sortedContractsActivity,
organizedAccountsActivity
};
}
fetchBlocksAndContractsAndAccounts();