0

the contract code is:


#[derive(Accounts)]
pub struct DepositToken<'info> {
    /// 项目方
    #[account(mut)]
    pub b_user: Signer<'info>,
    /// Token x mint for ex. USDC
    pub x_mint: Account<'info, Mint>,

    /// ATA of x_mint
    #[account(mut, constraint = b_x_token.mint == x_mint.key() && b_x_token.owner == b_user.key())]
    pub b_x_token: Account<'info, TokenAccount>,

    #[account(init, payer = b_user, space = Escrow::LEN)]
    pub escrow: Account<'info, Escrow>,

    #[account(
    init,
    payer = b_user,
    token::mint = x_mint,
    token::authority = escrow,
    )]
    pub escrowed_x_tokens: Account<'info, TokenAccount>,

    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>,
}

pub fn deposit(ctx: Context<DepositToken>, x_amount: u64) -> Result<()> {
        let escrow = &mut ctx.accounts.escrow;
        let (pda, _bump_seed) = Pubkey::find_program_address(&[ESCROW_PDA_SEED], ctx.program_id);
        escrow.authority = pda;
        escrow.escrowed_x_tokens = ctx.accounts.escrowed_x_tokens.key();
        anchor_spl::token::transfer(
            CpiContext::new(
                ctx.accounts.token_program.to_account_info(),
                anchor_spl::token::Transfer {
                    from: ctx.accounts.b_x_token.to_account_info(),
                    to: ctx.accounts.escrowed_x_tokens.to_account_info(),
                    authority: ctx.accounts.b_user.to_account_info(),
                },
            ),
            x_amount,
        )?;
        Ok(())
    }

the ts code is :

const tx = await program.methods.deposit(new anchor.BN(1))
            .accounts({
                bUser: provider.wallet.publicKey,
                xMint: x_mint.publicKey,
                bXToken: project_x_token,
                escrow: escrow,
                escrowedXTokens: escrowedXTokens.publicKey,
                tokenProgram: splToken.TOKEN_PROGRAM_ID,
                systemProgram: anchor.web3.SystemProgram.programId
            }).signers([escrowedXTokens]).rpc().catch((err) => {
                console.log("err:", err);
            });
        console.log("Your transaction signature", tx);

the error msg is :

err: Error: Signature verification failed

2 Answers 2

2

You can print the transaction to see which public keys are missing signatures. Looks like here you should be passing in the Keypair of the Escrow you're initializing.

1
  • 1
    As mentioned by @Truitt, the Escrow account needs to be included in the signers array since an account is required to sign during its creation.
    – Ademola
    Commented Dec 28, 2023 at 20:06
0

You must sign the transaction with b_user's keypair .

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.