I am creating a new SPL Token, and creating Associated Token Accounts for two wallets. The documentation indicates that the cost of creating a new Associated Token Account is ~0.00204428 Sol ($0.392808402), which is the rent-exempt amount. However, the first Token Account I create costs ~0.017666 Sol ($3.3945219). All subsequent created Token Accounts cost the rent-exempt amount of ~0.00204428 Sol. I am having the fiftyoneWallet as the payer for the creation of all of the Associated Token Accounts. Not sure why this is the case. Also, I'm not sure if there's an easier way to find the cost associated with creating an Associated Token Account without reading the before and after wallet balance. Here is my code:

const initialWalletBalance = await getWalletBalance("devnet", process.env.MY_PUBLIC_KEY, solPriceInUSD)
        // Get or Create Token Accounts:
        const fiftyoneTokenAccount = await getOrCreateAssociatedTokenAccount(
            { skipPreflight: true, commitment: "confirmed", preflightCommitment: "confirmed" }

        const secondWalletBalance = await getWalletBalance("devnet", process.env.MY_PUBLIC_KEY, solPriceInUSD)
        if (initialWalletBalance === undefined || secondWalletBalance === undefined) return

        console.log("first price difference USD",initialWalletBalance.balanceInUsd - secondWalletBalance.balanceInUsd)
        console.log("first price difference SOL",initialWalletBalance.balanceInSol - secondWalletBalance.balanceInSol)
const creatorTokenAccount = await getOrCreateAssociatedTokenAccount(
        const thirdWalletBalance = await getWalletBalance("devnet", process.env.MY_PUBLIC_KEY, solPriceInUSD)

        if (thirdWalletBalance === undefined) return
        console.log("second price difference USD",secondWalletBalance.balanceInUsd - thirdWalletBalance.balanceInUsd)
        console.log("second price difference SOL",secondWalletBalance.balanceInSol - thirdWalletBalance.balanceInSol)

Here are my logs:

first price difference USD 3.394521900000001
first price difference SOL 0.01766599999999996
second price difference USD 0.392808402
second price difference SOL 0.0020442800000000094

And here is the Get Wallet Balance Function:

import { Cluster, Connection, LAMPORTS_PER_SOL, PublicKey, clusterApiUrl } from "@solana/web3.js"

export default async function getWalletBalance(
    clusterType: Cluster,
    publicKeyString: string,
    solPriceInUSD: number
): Promise<
    void | { balanceInSol: number, balanceInUsd: number }
> {
    try {
        const connection = new Connection(clusterApiUrl(clusterType), "confirmed")

        const publicKey = new PublicKey(publicKeyString)
        const balanceInLamports = await connection.getBalance(publicKey)
        const balanceInSol = balanceInLamports / LAMPORTS_PER_SOL
        const balanceInUsd = balanceInSol * solPriceInUSD

        return {
    } catch (error) {
  • I can't seem to recreate this when running your code, do you have the transaction hash of the transaction taking 0.017 Sol?
    – Ahri
    Mar 26 at 4:41
  • Do you know how I can get the transaction hash of an Account (getOrCreateAssociatedTokenAccount returns an account)
    – Ariel
    Mar 31 at 0:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.