typeError:_bundlr_network_client__webpack_imported_module_0__使用metaplex.nfts()。

发布于 2025-02-08 03:27:25 字数 1297 浏览 1 评论 0原文

我正在使用 this metaplex javascript javascript SDK与NFTS一起工作Solana区块链。

在上传NFT的元数据时,我会收到以下错误: typeError:_bundlr_network_client_webpack_imported_module_0__不是构造

函数用于连接到metaplex的代码:

const fromWallet = Keypair.generate();
console.log(fromWallet);
const connection = new Connection(clusterApiUrl("devnet"));
const metaplex = Metaplex.make(connection)
 .use(keypairIdentity(fromWallet))
 .use(
   bundlrStorage({
     address: "https://devnet.bundlr.network",
     providerUrl: "https://api.devnet.solana.com",
     timeout: 60000,
   })
 );

上传元数据函数:

async function uploadMetadata() {
    try {
      const { uri, metadata } = await metaplex.nfts().uploadMetadata({
        name: formInput.name,
        image: image,
        description: formInput.description,
      });
      console.log(metadata.image);
      return uri;
    } catch (error) {
      console.log(`Error uploading metadata - ${error}`);
    }
  }

我无法理解为什么会遇到此错误。我试图通过从Metaplex配置中删除(Kepairidentity(Fromwallet))来达到该功能。但是,这样我就遇到了另一个错误。对于Metaplex的类似配置,mx.nfts()。findnftbymint(new publicKey(地址))正常工作。

任何帮助都将受到赞赏。谢谢。

I'm using this metaplex javascript SDK for working with nfts on solana blockchain.

While uploading the metadata for an nft, I am getting the following error:
TypeError: _bundlr_network_client__WEBPACK_IMPORTED_MODULE_0__ is not a constructor

Code for connecting to metaplex:

const fromWallet = Keypair.generate();
console.log(fromWallet);
const connection = new Connection(clusterApiUrl("devnet"));
const metaplex = Metaplex.make(connection)
 .use(keypairIdentity(fromWallet))
 .use(
   bundlrStorage({
     address: "https://devnet.bundlr.network",
     providerUrl: "https://api.devnet.solana.com",
     timeout: 60000,
   })
 );

Uploading metadata function:

async function uploadMetadata() {
    try {
      const { uri, metadata } = await metaplex.nfts().uploadMetadata({
        name: formInput.name,
        image: image,
        description: formInput.description,
      });
      console.log(metadata.image);
      return uri;
    } catch (error) {
      console.log(`Error uploading metadata - ${error}`);
    }
  }

I couldn't understand why I'm getting this error. I tried to hit the function by removing .use(keypairIdentity(fromWallet)) from metaplex configuration. But I am getting another error regarding undefined wallet that way. For the similar configuration of metaplex, mx.nfts().findNftByMint(new PublicKey(address)) is working correctly.

Any help is appreciated. Thank you.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛装女皇 2025-02-15 03:27:25

我正面临完全相同的问题
我在metaplex github repo https://github.com/metaplex-foundation/138“ js/essess/138

所以事实证明我们需要使用钱包适配器
Kepairidentity& WalletAdapterIdentity应该在浏览器上工作,但是只有Walletapteridentity对我有用。

Metaplex也创建的钱包适配器的链接是 https://github.com/solana-labs/钱包 - 适配器

更新,您只需要包装应用程序组件

import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { ConnectionProvider, useConnection, useWallet, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider, WalletMultiButton } from '@solana/wallet-adapter-react-ui';
import {
  GlowWalletAdapter,
  PhantomWalletAdapter,
  SlopeWalletAdapter,
  SolflareWalletAdapter,
  TorusWalletAdapter,
} from '@solana/wallet-adapter-wallets';
import { clusterApiUrl, PublicKey } from '@solana/web3.js';
import './App.css';
import '@solana/wallet-adapter-react-ui/styles.css';
import { useEffect, useState, useMemo } from "react";
import { Metaplex } from '@metaplex-foundation/js';

export const App = () => {
  return (
    <BrowserRouter>
      <Context>
        <Content />
      </Context>
    </BrowserRouter>
  );
};

const Context = ({ children }) => {

  const network = WalletAdapterNetwork.Devnet;
  const endpoint = useMemo(() => clusterApiUrl(network), [network]);


  const wallets = useMemo(
    () => [
      new PhantomWalletAdapter(),
      new GlowWalletAdapter(),
      new SlopeWalletAdapter(),
      new SolflareWalletAdapter({ network }),
      new TorusWalletAdapter(),
    ],
    [network]
  );

  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={wallets} autoConnect>
        <WalletModalProvider>{children}</WalletModalProvider>
      </WalletProvider>
    </ConnectionProvider>
  );
};

const Content = () => {
  const { connection } = useConnection();
  const wallet = useWallet();
  const metaplex = Metaplex.make(connection);
  const [walletAddress, setWalletAddress] = useState('');
  const [walletWarning, setWalletWarning] = useState(false);
  const [disabled, setDisabled] = useState(false);



  
  useEffect(() => {
    const onload = async () => {
      await checkIfWalletIsConnected();
    }
    window.addEventListener('load', onload);
    return () => window.removeEventListener('load', onload);
  }, []);





  return (
    <div className='main-app-container'>
      <div className='sec-app-container'>
        <WalletMultiButton/>
        <div className="router-container">
          <Routes>
            <Route exact path="/" element={<Landing walletWarning={walletWarning} />} />
            <Route exact path="/mint_interface"
              element={
                  <MintInterface wallet={wallet} connection={connection} />
              } />
          </Routes>
        </div>
      </div>
    </div >
  );
};


export default App;

和MintInterface组件,

import { useState } from 'react';
import { Form, Button, Spinner } from 'react-bootstrap';
import { WalletModalProvider, WalletMultiButton } from '@solana/wallet-adapter-react-ui';
import { Metaplex, keypairIdentity, walletAdapterIdentity, bundlrStorage } from '@metaplex-foundation/js';
import { Connection, clusterApiUrl, Keypair } from '@solana/web3.js';
import "./minting.css";


const cluster = "devnet";


function MintInterface({ wallet, connection }) {
   const [maturityDate, setMaturityDate] = useState("");
   const [quantity, setQuantity] = useState(1);
   const [loading, setLoading] = useState(false);




   const metaplex = Metaplex.make(connection)
       .use(walletAdapterIdentity(wallet))
       .use(
           bundlrStorage({
               address: "https://devnet.bundlr.network",
               providerUrl: "https://api.devnet.solana.com",
               timeout: 60000,
           })
       );
       );
}




export default MintInterface;

请确保在配置中使用WalletAdapterIdentity

I was facing the exact same issue
I opened an issue on metaplex github repo https://github.com/metaplex-foundation/js/issues/138

so it turned out we need to use the wallet adapter
keypairIdentity & walletAdapterIdentity should work on the browser however only walletAdapterIdentity worked for me .

the link to wallet adapter also created by metaplex is https://github.com/solana-labs/wallet-adapter

update, you just need to wrap you app component

import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { ConnectionProvider, useConnection, useWallet, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider, WalletMultiButton } from '@solana/wallet-adapter-react-ui';
import {
  GlowWalletAdapter,
  PhantomWalletAdapter,
  SlopeWalletAdapter,
  SolflareWalletAdapter,
  TorusWalletAdapter,
} from '@solana/wallet-adapter-wallets';
import { clusterApiUrl, PublicKey } from '@solana/web3.js';
import './App.css';
import '@solana/wallet-adapter-react-ui/styles.css';
import { useEffect, useState, useMemo } from "react";
import { Metaplex } from '@metaplex-foundation/js';

export const App = () => {
  return (
    <BrowserRouter>
      <Context>
        <Content />
      </Context>
    </BrowserRouter>
  );
};

const Context = ({ children }) => {

  const network = WalletAdapterNetwork.Devnet;
  const endpoint = useMemo(() => clusterApiUrl(network), [network]);


  const wallets = useMemo(
    () => [
      new PhantomWalletAdapter(),
      new GlowWalletAdapter(),
      new SlopeWalletAdapter(),
      new SolflareWalletAdapter({ network }),
      new TorusWalletAdapter(),
    ],
    [network]
  );

  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={wallets} autoConnect>
        <WalletModalProvider>{children}</WalletModalProvider>
      </WalletProvider>
    </ConnectionProvider>
  );
};

const Content = () => {
  const { connection } = useConnection();
  const wallet = useWallet();
  const metaplex = Metaplex.make(connection);
  const [walletAddress, setWalletAddress] = useState('');
  const [walletWarning, setWalletWarning] = useState(false);
  const [disabled, setDisabled] = useState(false);



  
  useEffect(() => {
    const onload = async () => {
      await checkIfWalletIsConnected();
    }
    window.addEventListener('load', onload);
    return () => window.removeEventListener('load', onload);
  }, []);





  return (
    <div className='main-app-container'>
      <div className='sec-app-container'>
        <WalletMultiButton/>
        <div className="router-container">
          <Routes>
            <Route exact path="/" element={<Landing walletWarning={walletWarning} />} />
            <Route exact path="/mint_interface"
              element={
                  <MintInterface wallet={wallet} connection={connection} />
              } />
          </Routes>
        </div>
      </div>
    </div >
  );
};


export default App;

and in the MintInterface Component

import { useState } from 'react';
import { Form, Button, Spinner } from 'react-bootstrap';
import { WalletModalProvider, WalletMultiButton } from '@solana/wallet-adapter-react-ui';
import { Metaplex, keypairIdentity, walletAdapterIdentity, bundlrStorage } from '@metaplex-foundation/js';
import { Connection, clusterApiUrl, Keypair } from '@solana/web3.js';
import "./minting.css";


const cluster = "devnet";


function MintInterface({ wallet, connection }) {
   const [maturityDate, setMaturityDate] = useState("");
   const [quantity, setQuantity] = useState(1);
   const [loading, setLoading] = useState(false);




   const metaplex = Metaplex.make(connection)
       .use(walletAdapterIdentity(wallet))
       .use(
           bundlrStorage({
               address: "https://devnet.bundlr.network",
               providerUrl: "https://api.devnet.solana.com",
               timeout: 60000,
           })
       );
       );
}




export default MintInterface;

make sure you use walletAdapterIdentity in the configuration

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文