错误:无法发送交易:交易模拟失败:错误处理指令0:指令无效帐户数据

发布于 2025-02-11 18:47:43 字数 1231 浏览 0 评论 0原文

我试图将Sol从编程性创建的钱包转移到用户钱包(撤回操作)。我读了文件,说应该创建PDA帐户。我创建了一个具有我有限的知识的文件,但遇到了此错误 我用于PDA和提取的Rust Code是:

let accounts_iter = &mut accounts.iter();
let coinflip_account = next_account_info(accounts_iter)?;
let wallet_account = next_account_info(accounts_iter)?;
let pda_account = next_account_info(accounts_iter)?;
let system_program = next_account_info(accounts_iter)?;
let withdraw = spl_token::instruction::transfer(
    system_program.key,
    coinflip_account.key,
    wallet_account.key,
    &pda_account.key,
    &[&pda],
    lamports,
)?;
msg!("amount {:?} Fani", lamports);

invoke_signed(
    &withdraw,
    &[
        system_program.clone(),
        wallet_account.clone(),
        coinflip_account.clone(),
        pda_account.clone()
    ],
    signers,
)?;

从打字稿中进行交易指令的密钥是:

keys: [
      { pubkey: coinflipPubKey, isSigner: false, isWritable: true },
      { pubkey: wallet.publicKey, isSigner: true, isWritable: true },
      { pubkey: pda, isSigner: false, isWritable: false },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
    ],

Coinflippubkey在哪里发件人,钱包是用户钱包 /接收器。

i was trying to transfer sol from programmatically created wallet to user wallet(withdraw operation).i read documents saying that pda accounts should be create .i created one with my limited knowledge but encountered this error
my rust code for pda and withdraw is:

let accounts_iter = &mut accounts.iter();
let coinflip_account = next_account_info(accounts_iter)?;
let wallet_account = next_account_info(accounts_iter)?;
let pda_account = next_account_info(accounts_iter)?;
let system_program = next_account_info(accounts_iter)?;
let withdraw = spl_token::instruction::transfer(
    system_program.key,
    coinflip_account.key,
    wallet_account.key,
    &pda_account.key,
    &[&pda],
    lamports,
)?;
msg!("amount {:?} Fani", lamports);

invoke_signed(
    &withdraw,
    &[
        system_program.clone(),
        wallet_account.clone(),
        coinflip_account.clone(),
        pda_account.clone()
    ],
    signers,
)?;

keys for transaction instruction from typescript is :

keys: [
      { pubkey: coinflipPubKey, isSigner: false, isWritable: true },
      { pubkey: wallet.publicKey, isSigner: true, isWritable: true },
      { pubkey: pda, isSigner: false, isWritable: false },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
    ],

where coinflipPubKey is sender ,wallet is user wallet / receiver.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文