I try to run this function in client, but I got an issue with it.

    try {
      const provider = getProvider();
      const program = new Program(idl, provider);
      const accounts = {
        accounts: {
          campaign: publicKey,
          user: provider.wallet.publicKey,
          systemProgram: SystemProgram.programId
      await program.methods.donate(new BN(0.5) * web3.LAMPORTS_PER_SOL, accounts).rpc();
      console.log("Donated some money to: ", publicKey.toString());
    } catch (error) {
      console.log("Error: ", error);

browser throw a catch error, told me that "Error:  Error: provided too many arguments 0,[object Object],[object Object] to instruction donate expecting: amount". Although, I ensure that I passed right args. Here is **donate** function in Rust.

```pub fn donate(ctx: Context<Donate>, amount: u64) -> ProgramResult {
        let ix = transfer(
        let _ = invoke(
        (&mut ctx.accounts.campaign).amount_donated += amount;

and derive account struct.

pub struct Donate<'info> {
    pub campaign: Account<'info, Campaign>,
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,

1 Answer 1


You should convert to this new BN(0.5 * web3.LAMPORTS_PER_SOL)

await program.methods.donate(new BN(0.5 * web3.LAMPORTS_PER_SOL)).accounts({ campaign: publicKey, user: provider.wallet.publicKey, systemProgram: SystemProgram.programId }).rpc();

  • Thank you. I resolved it, coral-xyz/anchor @0.3.0 Commented Apr 23 at 4:55

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.