So I have been trying to make a program to just transfer some SOL from one account to another.
pub fn fund_vault(ctx: Context<FundVault>) -> Result<()> {
let payer = &mut ctx.accounts.payer;
let receiver = &mut ctx.accounts.vault;
let amount: u64 = 1_000_000_000;
if payer.lamports() < amount {
return Err(error!(ErrorCode::NotEnoughSol));
}
let instruction = transfer(&payer.key(), &receiver.key(), amount);
let account_infos = [
payer.to_account_info().clone(),
receiver.to_account_info().clone(),
ctx.accounts.system_program.to_account_info().clone(),
];
invoke(&instruction, &account_infos)?;
Ok(())
}
with this context
#[derive(Accounts)]
pub struct FundVault<'info> {
#[account(mut, seeds = [b"vault"], bump)]
pub vault: Account<'info, Vault>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
}
essentially I am trying to send SOL from payer to the vault, I have also tried to change the vault to be a simple Account (not PDA)
my typescript test code looks like this
const newUser = anchor.web3.Keypair.generate();
let airdropSig = await provider.connection.requestAirdrop(
newUser.publicKey,
5 * anchor.web3.LAMPORTS_PER_SOL,
);
const latestBlockHash = await provider.connection.getLatestBlockhash();
await provider.connection.confirmTransaction({
blockhash: latestBlockHash.blockhash,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
signature: airdropSig,
});
const tx2 = await program.methods
.fundVault()
.accounts({
payer: newUser.publicKey,
vault: pdaVaultPublicKey,
})
.signers([newUser])
.rpc();
so I am creating a keypair, funding it with some SOL and trying to invoke the fundVault method. But I am always getting this error
Error: failed to send transaction: Transaction simulation failed: This account may not be used to pay transaction fees
at Connection.sendEncodedTransaction (node_modules/@solana/web3.js/src/connection.ts:4546:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at Connection.sendRawTransaction (node_modules/@solana/web3.js/src/connection.ts:4505:20)
at sendAndConfirmRawTransaction (node_modules/@project-serum/anchor/src/provider.ts:288:21)
at AnchorProvider.sendAndConfirm (node_modules/@project-serum/anchor/src/provider.ts:148:14)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:29:16)
Anybody having an idea what is going on? Is it possible that the owner of the generated account is not system program?