Reputation: 31
I try to send a transaction with an instruction to an onchain program in SOLANA. I get this error : Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: instruction spent from the balance of an account it does not own
My Javascript code is :
var solana_web3 = require('@solana/web3.js');
const { SSL_OP_EPHEMERAL_RSA } = require('constants');
const url = 'https://devnet.solana.com' ;
const sigSecretKey1 = [39,90,157,237,...] ;
const sigSecretKey2 = [39,90,157,237,...] ;
const progID = 'FpbcvcsCB...' ;
connection = new solana_web3.Connection(url, 'singleGossip');
const account_signer_source = new solana_web3.Account( Buffer.from(sigSecretKey1) );
const account_signer_destination = new solana_web3.Account( Buffer.from(sigSecretKey2) );
const pub_programId = new solana_web3.PublicKey(progID) ;
const instruction = new solana_web3.TransactionInstruction({
keys: [
{pubkey : account_signer_source.publicKey, isSigner : true, isWritable: true},
{pubkey : account_signer_destination.publicKey, isSigner : false, isWritable: true},
],
programId : pub_programId,
data: Buffer.from([]),
});
const transaction = new solana_web3.Transaction().add(instruction);
//transaction.addSignature(account_signer_source.publicKey, Buffer.from(sigSecretKey1));
await solana_web3.sendAndConfirmTransaction(
connection,
transaction,
[account_signer_source],
{commitment: 'singleGossip', preflightCommitment: 'singleGossip',}
).then(()=>{console.log('done')}).catch((e)=>{console.log(e)});
Could you help me please ?
Thx Reza
Upvotes: 3
Views: 4831
Reputation: 1015
you're taking away lamports from an account that the program doesn't own. You can only deduct lamports from accounts owned by the program, ie my token-swap program can deduct lamports on all accounts that it owns, and no others. If you want to move lamports within your program, you need to invoke system_instruction::transfer
Upvotes: 3
Reputation: 128
The error message basically means the program is not the owner of the account whose balance being spent.
Upvotes: 1