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());
getCampaign();
} 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(
&ctx.accounts.user.key(),
&ctx.accounts.campaign.key(),
amount,
);
let _ = invoke(
&ix,
&[
ctx.accounts.user.to_account_info(),
ctx.accounts.campaign.to_account_info(),
],
);
(&mut ctx.accounts.campaign).amount_donated += amount;
Ok(())
}```
and derive account struct.
```#[derive(Accounts)]
pub struct Donate<'info> {
#[account(mut)]
pub campaign: Account<'info, Campaign>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}```