2

I'm trying to make a program that's able to get mint authorization on a PDA (first function), and then mint tokens using that authorization. My transfer authorization function works fine (tested on devnet), but I can't get the mint to work. I keep getting "Cross-program invocation with unauthorized signer or writable account." error.

On most of the exemples for a minting function, the mint (the token) is created by the program. Here that's not the case. I guess I'm doing something wrong there?

Also, I'm forced to clone another_authority so I don't do a mutable and immutable borrow in the same scope. Is it wrong?

2 Answers 2

5

Your seeds in the second method is different from the first, you forgot to add the b"autho" prefix. Make the following change and your code is good to go:

 let seeds: &[&[u8]] = &[
     b"autho",                          // Seed 0: autho PREFIX
     another_authority.admin.as_ref(),  // Seed 1: Admin's public key
     bump_seed,                         // Seed 2: Bump nonce
 ];

 let signer_seeds = &[&seeds[..]];

2
  • Indeed, it now works. Thanks a lot! Commented Jan 2 at 15:59
  • Great! If it worked, you can accept the answer to close the question.
    – 0xShuk
    Commented Jan 2 at 16:03
2

Just at quick glance, it looks like you are not passing in all your seeds in your minting function. Specifically, I think you need to add b"autho" into your seeds declaration.

Here's an example similar to yours: https://github.com/solana-developers/program-examples/blob/d6cd69d8df3eb95966b3d2361ede84529413567a/tokens/pda-mint-authority/anchor/programs/token-minter/src/instructions/mint.rs#L46

FYI you can also use the seeds constraint in your Minting struct to help ensure you're passing a valid PDA (it's not limited to use only with init).

1
  • Indeed, it now works. Thanks a lot! Commented Jan 2 at 15:59

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.