mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-22 07:36:44 +00:00
feat: get tps
This commit is contained in:
17
src/tools/get_tps.ts
Normal file
17
src/tools/get_tps.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
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;
|
||||
}
|
||||
@@ -7,3 +7,4 @@ export * from "./transfer";
|
||||
export * from "./trade";
|
||||
export * from "./register_domain";
|
||||
export * from "./lend";
|
||||
export * from "./get_tps";
|
||||
|
||||
Reference in New Issue
Block a user