0

Using getOrCreateAssociatedTokenAccount is there a way to determine the cost associated with opening a new Associated Token Account? The function returns an Account.

2 Answers 2

1

The getOrCreateAssociatedTokenAccount function doesn't directly return the cost. One way to do that would be Simulating the Transaction.

This approach involves simulating the transaction that calls getOrCreateAssociatedTokenAccount before actually sending it. The simulation provides an estimate of the transaction fees based on current network conditions.

You can read more about it using the link below:

https://spl.solana.com/associated-token-account

1
  • How can I simulate the transaction using Solana's javascript sdk?
    – Ariel
    Commented Apr 15 at 20:08
1

To simulate the transaction using Solana's js sdk:

  1. Install @solana/web3.js
  2. Import the necessary libraries needed: const { Connection, Transaction, SystemProgram, Keypair, Token, associatedToken } = require("@solana/web3.js"); (these are all placeholders)
  3. Next to simulate the transaction:
  • create a new Transaction object.
  • then add an instruction to associatedToken.getOrCreateAssociatedTokenAccount to retrieve or create the ATA for the specified mintPublicKey and ownerPublicKey.
  • Finally, it should simulate the transaction using connection.simulateTransaction and logs the estimated rent_fee.

From my understanding these are what are needed to simulate the transaction using Solana's javascript sdk. You can read more about it here: https://solana.com/docs/core/transactions

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.