2

我正在开发一个借贷协议的前端,用户列出 NFT 以在 Solana 上借贷。我收到一个错误createListing

await program.instruction.createListing(
        listingBump,
        params, {  
        accounts: {
          owner: wallet.publicKey,
          listing: listingPubkey,
          nftAccount: shipAccount,
          nftMint: shipMint.publicKey,
          collateralMint: collateralMint.publicKey,
          feeDestination: feeDestination,
          feeMint: atlasMint.publicKey,
          tokenProgram: TOKEN_PROGRAM_ID, 
          systemProgram: SystemProgram.programId,
        },
    signers: [wallet]
});

这是错误:Error while creating the listing TypeError: s.TransactionInstruction is not a constructor at Object.r [as createListing] (main-packed.js:1175) at Object.createListing (solana.js:915)这是引发它的行(在包装上):

var Y = Object.freeze({
  __proto__: null,
  invoke: async function (t, e, n, i) {
    t = Q(t), i || (i = w());
    const s = new s.Transaction();
    return s.add(new s.TransactionInstruction({
      programId: t,
      keys: null != e ? e : [],
      data: n
    })), await i.send(s);
  },
  getMultipleAccounts: H
});

我不确定是什么引发了错误。另外,必须注意我使用的是纯 JS,因为我正在使用 Dart-JS 互操作在 Flutter 中进行开发。所以我不得不使用 Browserify/Esmify 包来捆绑所有需要的包并将它们暴露给互操作。也许这与问题有关。

4

1 回答 1

0

我在 ClojureScript 中遇到了这个错误,在挠了 3 天之后,我找到了解决方案。

anchor-ts客户端rollup用于为浏览器捆绑 ts 代码。在捆绑过程中,它通过一个名为rollup-plugin-terser.

更简洁的代码以@solana/web3.js重用分配给导入的变量的方式来处理代码。

即:在最终输出中会发生这样的事情

var s = require("@solana/web3.js")

function x() {
  var s, a, b; // ----> redefined s
  ...
  s.TransactionInstruction() // ----> calls method on original s
}

我分叉了锚并摆脱了 terser 插件。这为我解决了错误。

于 2022-02-03T00:32:07.143 回答