0

I’m trying to send SOL to a “hold account” (which I’m thinking should be a PDA) and then only be able to claim it from the address that sent this SOL. I am getting an error as I’m trying to now call the “send_sol” instruction client side.

lib.rs

#[derive(Accounts)]
pub struct SendSOL<'info> {
    #[account(mut)]
    pub owner: Signer<'info>,  // The sender of the SOL, the one who will sign the transaction

    #[account(
        init,  // Initialize the hold account (PDA) on this transaction
        payer = owner,  // The owner will pay for the account creation and rent
        seeds = [b"hold_account", owner.key().as_ref()],  // PDA derivation using a seed
        bump,  // Bump seed for the PDA
        space = 8 + HoldAccount::INIT_SPACE  // Space for storing account (8 bytes for SOL storage)
    )]
    pub hold_account: Account<'info, HoldAccount>,  // This is where SOL will be held (PDA for temp hold)

    #[account(mut)]
    pub from_account: SystemAccount<'info>,  // The account sending SOL

    pub system_program: Program<'info, System>,  // The system program handles SOL transfers
}

Here is my .tsx file where I’m trying to be able to successfully call the send_sol instruction:

const sendSOL = useMutation({
    mutationKey: ['pogo', 'send_sol', { cluster }],
    mutationFn: async ({ keypair, amount, message }: { keypair: Keypair, amount: number, message: string }) => {

      // Interact with the Anchor program to invoke send_sol
      return await program.methods
        .sendSol(new anchor.BN(amount * 10 ** 9), message)  // Send SOL in lamports (1 SOL = 10^9 lamports)
        .accounts({
          owner: keypair.publicKey!,
          hold_account: await PublicKey.createWithSeed(keypair.publicKey!, "hold_account", programId),  // The derived PDA
          from_account: keypair.publicKey!,
          system_program: SystemProgram.programId,
        })
        .rpc()
    },
    onSuccess: (signature) => {
      transactionToast(signature)
    },
    onError: (error) => {
      console.error('Transaction Error:', error)
    }
  })

I get this error on “hold_account”:

Object literal may only specify known properties, and 'holdAccount' does not exist in type 'ResolvedAccounts<{ name: "owner"; writable: true; signer: true; } | { name: "holdAccount"; writable: true; pda: { seeds: [{ kind: "const"; value: [104, 111, 108, 100, 95, 97, 99, 99, 111, 117, 110, 116]; }, { ...; }]; }; } | { ...; } | { ...; }>'.

For additional context, here is the relevant code in my IDL:

{
      "name": "send_sol",
      "discriminator": [
        214,
        24,
        219,
        18,
        3,
        205,
        201,
        179
      ],
      "accounts": [
        {
          "name": "owner",
          "writable": true,
          "signer": true
        },
        {
          "name": "hold_account",
          "writable": true,
          "pda": {
            "seeds": [
              {
                "kind": "const",
                "value": [
                  104,
                  111,
                  108,
                  100,
                  95,
                  97,
                  99,
                  99,
                  111,
                  117,
                  110,
                  116
                ]
              },
              {
                "kind": "account",
                "path": "owner"
              }
            ]
          }
        },
        {
          "name": "from_account",
          "writable": true
        },
        {
          "name": "system_program",
          "address": "11111111111111111111111111111111"
        }
      ],
      "args": [
        {
          "name": "amount",
          "type": "u64"
        },
        {
          "name": "message",
          "type": "string"
        }
      ]
    },

1 Answer 1

0

This worked out for me, though I don't quite understand why there was an issue!

https://solana.stackexchange.com/a/14800/26650

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.