blockchain - How to send a transaction to an onchain program in solana with javascript? - Stack Overflow

I try to send a transaction with an instruction to an onchain program in SOLANA.I get this error :Err

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 = '' ;
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],
    {mitment: 'singleGossip', preflightCommitment: 'singleGossip',}
).then(()=>{console.log('done')}).catch((e)=>{console.log(e)});

Could you help me please ?

Thx Reza

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.' ;
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],
    {mitment: 'singleGossip', preflightCommitment: 'singleGossip',}
).then(()=>{console.log('done')}).catch((e)=>{console.log(e)});

Could you help me please ?

Thx Reza

Share Improve this question asked Feb 26, 2021 at 15:34 Reza SReza S 311 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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

The error message basically means the program is not the owner of the account whose balance being spent.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745562199a4633173.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信