0

I'm currently working on a fundraising program which involves just transacting Sol.

In the first image, I have set fundraiser_config as the authority over the token_vault enter image description here

In the second image, I'm transferring Sol from the token_vault to the fundraiser_sol_token_account enter image description here

In the third image, I'm writing the test for fundraiser_withdrawal (ie second image ). However, the error is saying that it is an unknown signer. enter image description here

Please let me know what I have missed out as I have been stuck on this for a while. Thank you!

1
  • 1
    Please use code snippets rather than images
    – vicyyn
    Commented Aug 25, 2022 at 13:12

1 Answer 1

1

You're missing two accounts for fundraiserWithdrawal in your typescript code: fundraiser and token vault. Add them.

For the rust code, here's example code of me doing something similar, transferring spl-tokens from a token vault with a PDA as its authority:

let transfer_instruction = Transfer {
    from: funds_pot.to_account_info(),
    to: destination_account.to_account_info(),
    authority: campaign.to_account_info(),
};

let campaign_seeds = &[
    b"campaign".as_ref(),
    fundstarter.key.as_ref(),
    &[campaign.bump],
];

let signer = &[&campaign_seeds[..]];

let cpi_ctx = CpiContext::new(token_program.to_account_info(), transfer_instruction)
    .with_signer(signer);
anchor_spl::token::transfer(cpi_ctx, amount_to_withdraw)?;

Here campaign is a PDA whose seeds are used as signer for the instruction because it's the authority of the funds_pot token account.

9
  • Hey man, thanks for pointing that out! I have added in those 2 accounts but its throwing another error.. However, after thinking about it, since I'm setting vault_authority as pda over the token_vault, would it make more sense for the pda to sign this instruction instead? Given that I'm still getting the error message of unknown signer
    – bubu59
    Commented Aug 26, 2022 at 14:12
  • The authority in the accounts struct for the Transfer instruction has to be the authority of the from account(In this case token_vault). If it's a PDA then your signer argument should be gotten from whatever its seeds are.
    – Ademola
    Commented Aug 26, 2022 at 19:39
  • oooh.. okok. So what I did was added in this piece of code in CreateCampaign struct #[account( init, seeds = [b"vault", fundraiser_config.key().as_ref()], bump, payer = fundraiser, token::mint = sol_mint, token::authority = token_vault )] pub token_vault: Box<Account<'info, TokenAccount>>,
    – bubu59
    Commented Aug 27, 2022 at 9:29
  • Would doing the above means that fundraiser_config is now the authority of the token_vault ?
    – bubu59
    Commented Aug 27, 2022 at 9:37
  • After having added the seeds in, I went on to follow the example you gave above by providing the seeds in to to do the transfer of tokens from token_vault . However, in my test script, it still throws an error saying the signer is unknown
    – bubu59
    Commented Aug 27, 2022 at 9:39

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.