1

I know how ATA and PDA works. I know that an ATA is a PDA, and so the account which the PDA was derived from is the one that can sign transactions for this PDA. So, I assume that a contract's ATA's authority is the contract itself.

How can I specify this in an Anchor Instruction ?

Here is the code I'm trying to fix:

    pub token_mint: Account<'info, Mint>,

    #[account(
        mut,
        associated_token::mint = token_mint,
        associated_token::authority = ????,
    )]
    pub program_token_account: Box<Account<'info, TokenAccount>>,

1 Answer 1

1

You could create a PDA authority and use this instead as the authority of the ATA.

    #[account(
        mut,
        associated_token::mint = token_mint,
        associated_token::authority = vault_Account,
    )]
    pub program_token_account: Box<Account<'info, TokenAccount>>,

    #[account(mut)]
    pub vault_Account: Account<'info, VaultAccount>,

Using the program as the authority would mean that you'd need to use the Program Keypair to sign for transactions which I don't think is safe and practical.

Check out how we did it on soundwork with our market contracts

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.