MCPcopy Create free account
hub / github.com/ExtropyIO/SolanaBootcamp / feesEstimate

Function feesEstimate

utils/utils.ts:39–62  ·  view source on GitHub ↗
(connection: Connection, payer: Keypair)

Source from the content-addressed store, hash-verified

37}
38
39export async function feesEstimate(connection: Connection, payer: Keypair): Promise<number> {
40 const { blockhash } = await connection.getLatestBlockhash();
41
42 const messageArgs: MessageArgs = {
43 recentBlockhash: blockhash,
44 instructions: [],
45 header: {
46 numRequiredSignatures: 1,
47 numReadonlySignedAccounts: 0,
48 numReadonlyUnsignedAccounts: 0,
49 },
50 accountKeys: [payer.publicKey],
51 }
52
53 const message = new Message(messageArgs);
54 const feeCalculator = await connection.getFeeForMessage(message);
55
56 if (feeCalculator.value === null) {
57 throw new Error("Failed to retrieve fee calculator value");
58 }
59 let fees = feeCalculator.value * 100;
60
61 return fees;
62}
63
64export async function topUp(
65 connection: Connection,

Callers 1

establishEnoughSolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected