4
SPL.createAssociatedTokenAccount(connection, wallet, mint, project, {skipPreflight: true}, undefined, SPL.ASSOCIATED_TOKEN_PROGRAM_ID).then((projectTokenAccount) => {
      const mintIx = SPL.createMintToInstruction(mint, projectTokenAccount, wallet.publicKey, 2500000, undefined, undefined)

      const tx = new Transaction().add(mintIx)

      connection.sendTransaction(tx, [wallet], {skipPreflight: true}).then((signature) => {
            console.log(signature)
      })
})

When I set

project = new PublicKey("A PROGRAM Pubkey")

everything gets created and unlogically I can create an ATA with a PROGRAM as an owner (which can't sign CPI for itself).

when I set

project = new PublicKey("<A PDA which owner is the above PROGRAM>")

Then It give me an error: TokenOwnerOffCurveError

Shouldn't I be able to manage ATA from a program by creating PDAs first to associate them univoquely to a Mint ? But I can't create ATA for those PDA (my PDA have as seed the mint in order to make them univoque for each mint)

Edit: Solved It using the function getOrCreateAssociatedTokenAccount which allows me to set allowOwnerOffCurve = true

But what is the motivation behind this allowOwnerOffCurve necessity?

3
  • The error says it all.
    – Frank C.
    Oct 14, 2022 at 14:12
  • 1
    To create an ATA for a PDA you can set the allowOwnerOffCurve to true for getAssociatedTokenAddress function once you have the address you can call createAssociatedTokenAccountInstruction you also have the option to create the ATA from the program itself
    – Pratik.js
    Oct 14, 2022 at 16:13
  • @Pratik.js's answer is correct -- could you turn it into an answer?
    – Jon C
    Oct 18, 2022 at 16:36

1 Answer 1

3

To create an ATA for a PDA you can set the allowOwnerOffCurve to true for getAssociatedTokenAddress function once you have the address you can call createAssociatedTokenAccountInstruction you also have the option to create the ATA from the program itself

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.