mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-20 15:10:38 +00:00
18 lines
469 B
TypeScript
18 lines
469 B
TypeScript
import { SolanaAgentKit } from "../index";
|
|
|
|
export async function getTPS(agent: SolanaAgentKit): Promise<number> {
|
|
const perfSamples = await agent.connection.getRecentPerformanceSamples();
|
|
|
|
if (
|
|
!perfSamples.length ||
|
|
!perfSamples[0]?.numTransactions ||
|
|
!perfSamples[0]?.samplePeriodSecs
|
|
) {
|
|
throw new Error("No performance samples available");
|
|
}
|
|
|
|
const tps = perfSamples[0].numTransactions / perfSamples[0].samplePeriodSecs;
|
|
|
|
return tps;
|
|
}
|