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?
allowOwnerOffCurve
to true for getAssociatedTokenAddress function once you have the address you can callcreateAssociatedTokenAccountInstruction
you also have the option to create the ATA from the program itself