4

I am trying to pass remaining_accounts from the client side using the Anchor SDK, with the following code.

 const tx = await program.rpc.sendMonies(new anchor.BN(0), new anchor.BN(100), {
      accounts: {
        baseAccount: baseAccount.publicKey,
        remainingAccounts: [
          {pubkey: _ac1.publicKey, isWritable: true, isSigner: false},
          {pubkey: _ac2.publicKey, isWritable: true, isSigner: false},
          {pubkey: _ac3.publicKey, isWritable: true, isSigner: false}
        ],
        user: payingUser.publicKey
      },
      signers: [payingUser]
    });

Below is my program, where I log the number of remaining_accounts passed but, as you can see in the logs of this transaction the statement after "now transfer sol" logs 0. I even have a for-loop to iterate over the array of remaining accounts but that also doesn't run as the array is always empty.

msg!("now transfer sol");
msg!(ctx.remaining_accounts.len().to_string().as_str());

What am I doing wrong here? I highly suspect it is a problem with how I am passing the remaining accounts from the frontend.

1
  • you cite logs, but none were included in the post
    – trent.sol
    Commented Jul 23, 2022 at 17:51

1 Answer 1

6

Remaining accounts shouldn't be inside accounts, it's its own top level thing.

Like so

await program.rpc.sendMonies(new anchor.BN(0), new anchor.BN(100), {
      accounts: {
        baseAccount: baseAccount.publicKey,
        user: payingUser.publicKey
      },
      remainingAccounts: [
          {pubkey: _ac1.publicKey, isWritable: true, isSigner: false},
          {pubkey: _ac2.publicKey, isWritable: true, isSigner: false},
          {pubkey: _ac3.publicKey, isWritable: true, isSigner: false}
        ],
      signers: [payingUser]
    });

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.