estimateTransferFee
Estimates total cost to transfer a token, optionally including rent for creating the recipient ATA.
Usage
page.tsx
import { useConnection } from "@solana/wallet-adapter-react";
import { estimateTransferFee } from "@okito/sdk";
import { getAssociatedTokenAddress } from "@solana/spl-token";
import { PublicKey } from "@solana/web3.js";
const MyComponent = () => {
const { connection } = useConnection();
const getFeeEstimate = async (recipientAddress: string, mintAddress: string) => {
try {
const needsDestinationATA = false;
const priorityFee = 5000; // Optional priority fee
const feeInfo = await estimateTransferFee(connection, needsDestinationATA, priorityFee);
console.log("Estimated Fee (in lamports):", feeInfo.estimatedFee);
alert(`Estimated transfer cost: ${feeInfo.estimatedFee / 1e9} SOL`);
} catch (e) {
console.error("Failed to get fee estimate:", e);
}
};
// ... your component JSX
};
Parameters
Name | Type | Default |
---|---|---|
connection | Connection Solana connection instance. |
|
needsDestinationATA | boolean Set true if the recipient lacks an ATA for this mint. |
|
priorityFee | number Optional priority fee in micro‑lamports to improve processing priority. |
|
Response
Name | Type | Default |
---|---|---|
estimatedFee | number Estimated fee in lamports. |
|
Last updated on