Reputation: 11
I'm working on learning Solana full stack using Anchor. I've run into a problem with signing a transaction sending Sol to a PDA owned by a program I'm making. I'm unable to call the rpc for the function with the proper signatures. Below is my code:
await program.rpc.payPool(pool.data.name, new BN(payment), {
accounts: {
pool: pool.publicKey,
poolOwner: owner.key.PublicKey,
user: adder.key.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [
adder.key,
// I need to put another signature here I think
],
});
The error I'm getting is, which I think is related to a problem varying the transaction.
Error: Invalid arguments: poolOwner not provided.
at ~/learnsolana/node_modules/@project-serum/anchor/dist/cjs/program/common.js:39:23
at Array.forEach (<anonymous>)
at validateAccounts (node_modules/@project-serum/anchor/dist/cjs/program/common.js:33:16)
at ix (node_modules/@project-serum/anchor/dist/cjs/program/namespace/instruction.js:34:46)
at txFn (node_modules/@project-serum/anchor/dist/cjs/program/namespace/transaction.js:16:20)
at Object.rpc [as payPool] (node_modules/@project-serum/anchor/dist/cjs/program/namespace/rpc.js:28:24)
at payPool (tests/learnsolana.js:70:23)
at Context.<anonymous> (tests/learnsolana.js:117:28)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
The relevant information from the Solana program is:
pub fn pay_pool(ctx: Context<PayPool>, _pool_name: String, payment: u64,) ->
ProgramResult {
let user = &ctx.accounts.user;
let pool = &mut ctx.accounts.pool;
if pool.payers.len() >= pool.capacity as usize {
return Err(PoolError::PayersFull.into());
}
pool.payers.push(*user.to_account_info().key);
invoke(
&transfer(
user.to_account_info().key,
pool.to_account_info().key,
payment,
),
&[
user.to_account_info(),
pool.to_account_info(),
ctx.accounts.system_program.to_account_info(),
],
)?;
Ok(())
}
#[derive(Accounts)]
#[instruction(pool_name: String, payment: u64)]
pub struct PayPool<'info>{
#[account(mut, has_one=pool_owner @ PoolError::WrongPoolOwner, seeds=[b"pool", pool_owner.to_account_info().key.as_ref(), name_seed(&pool_name)], bump=pool.bump)]
pub pool: Account<'info, Pool>,
pub pool_owner: AccountInfo<'info>,
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct Pool {
pub pool_owner: Pubkey,
pub bump: u8,
pub capacity: u16,
pub name: String,
pub payers: Vec<Pubkey>,
}
Any help is appreciated. Thank you.
Upvotes: 1
Views: 2075
Reputation: 21
poolOwner: owner.key.PublicKey
-> poolOwner: owner.key.publicKey
You just need to lower case the "P" in publicKey. You also shouldn't need to provide the signers
param as anchor will generate that automatically.
Upvotes: 2