javascript - 如何使用 javascript 将交易发送到 solana 中的链上程序?
问题描述
我尝试向 SOLANA 中的链上程序发送带有指令的交易。我收到此错误: 错误:发送交易失败:交易模拟失败:错误处理指令 0:指令从它不拥有的帐户余额中花费
我的 Javascript 代码是:
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)});
请问你能帮帮我吗 ?
谢谢礼萨
解决方案
您正在从该程序不拥有的帐户中取走灯。您只能从程序拥有的帐户中扣除灯,即我的代币交换程序可以在它拥有的所有帐户上扣除灯,而不能从其他帐户中扣除灯。如果你想在你的程序中移动灯,你需要调用 system_instruction::transfer
推荐阅读
- excel - 如何提取(行和列的第一个单元格)修改后的单元格放入数组,excel vba?
- angular - 如何在 batton 中获取 gridview 绑定数据单击角度和类型脚本中的 gridview 外部
- c++ - 无法正确遍历文件
- node.js - 如何将节点参数 max-http-header-size 传递给 Firebase 函数
- python - 'function' 对象在 Python 中不可下标
- google-sheets - 有没有办法从 Google 表格单元格中获取“标题文本”?
- java - resolveFully 不解析与回调相关的 PathItem 的嵌套引用或普通引用
- javascript - 任意数量页面的 ReactJS 上下文
- python - 如何解决在 Python 3.8 上运行的 PyCharm 上安装 XG-Boost 时遇到的这个问题?
- python - python准备的请求-删除不需要的标头