1

Facing verification failed issue and found many similar issues on StackExchange but couldn't solve my problem so posting here.

I have deployed a staking program on devnet. It initiates spl_token transfer from user's token account to its own token account.

After connecting wallet, when frontend react app calls the rust program for staking spl tokens, I get signature verification error:

{"code":-32003,"message":"failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account"}

You can try to run the client after setting solana config to devnet.

I checked the documentation and also discussed the issue with peers. Unfortunately the issue persisted. All help is appreciated!

4
  • Please provide additional details to make answering your question easier. As it's currently written, it's difficult to give an answer without extra information. A code sample giving the full picture of the instruction and validator would be pretty helpful
    – Ademola
    Aug 4, 2022 at 20:35
  • Sure, let me share a modified version of the code after removing legally bound information.
    – Krati Jain
    Aug 5, 2022 at 13:10
  • @Ademola I added links for both rust program and client code in my post. Please check and confirm what I might be doing wrong. Thanks!
    – Krati Jain
    Aug 9, 2022 at 18:17
  • Use the try..catch pattern to catch the error and log it. That'll give you more information
    – Ademola
    Aug 10, 2022 at 23:52

3 Answers 3

3

You marked your ata accounts as signers.

{
    is_signer: true,
    is_writable: true,
    pubkey: userAta,
},
{
    is_signer: true,
    is_writable: true,
    pubkey: stakingProgramAssociatedTokenAccount,
},

Also you will have to create the token accounts after you generate their address. Check out the cookbook to learn more about the generating vs creating pdas.

https://solanacookbook.com/references/accounts.html#create-a-pda

2
  • thanks @Ryan! I modified my client code to change ATA to not be signers and also creating token accounts. I am still facing the same error. Can you please try to run the client and check what might be wrong. Will really appreciate :)
    – Krati Jain
    Aug 10, 2022 at 11:33
  • Finally I was able to solve the issue. I had to approve my program to be able to transfer tokens.
    – Krati Jain
    Aug 11, 2022 at 6:53
2

So usually when I get this error it's due to the fact that the signer I am passing is wrong or due to the account not being marked as mutable and most number of times when i get stuck it's due to the fact the account not being mutable.

1
  • Hi @pratik! thanks for the pointers. I checked my code as per your hints but it seems to be some other issue. Would you mind running the client code once and debugging on what is exactly the issue.
    – Krati Jain
    Aug 10, 2022 at 11:48
1

So I was able to solve the issue successfully. I needed to explicity approve my Rust program to be able to transfer tokens from user's associated token account to my Rust program's associated token account. Just be adding this code in my Rust program I was able to get it working:

         let ix = spl_token::instruction::approve(
          token_program.key,
          source_token_account.key,
          destination_token_account.key,
          initializer.key,
          &[initializer.key],
          amount,
         )?;

        invoke(
            &ix,
            &[
        source_token_account.clone(),
        destination_token_account.clone(),
        initializer.clone(),
        token_program.clone(),
            ],
        )?;
        msg!(
            "approved tx"
        );

In case others face the same issue in future, I have pushed the fully working code in this link: https://github.com/jainkrati/spl_token_staking_client_code

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.