Scikit Web

Solana NFT Metaplex js Metadata Create 솔라나 NFT JS 라이브러리 메타데이터 생성 과 information to the bundler: 400 Invalid tx 해결 본문

NFT/Solana(솔라나)

Solana NFT Metaplex js Metadata Create 솔라나 NFT JS 라이브러리 메타데이터 생성 과 information to the bundler: 400 Invalid tx 해결

Keun0 2022. 6. 19. 06:41
728x90
반응형

솔라나 NFT를 개발하기 위해서 사용되는 라이브러리들 중 가장 잘 된다고 생각하는 라이브러리 이다.

 

솔라나 쿡북에 있는 @metaplex/js 는.. 개발 가이드 대로 뭔가 너무 많이 안되고..

 

찾다 보니 @metaplex-foundation/js 이 있었다.

 

bundlrStorage 의 기본 정보가 메인넷을 바라보고 있어 그냥 사용하면 information to the bundler: 400 Invalid tx가  발생한다

 

아래 예제는 개발서버를 바라보고 있기 때문에 개발서버 주소로 변경하고 실행해야 한다. 그 후 솔 스캔으로 확인한다

 

https://github.com/metaplex-foundation/js#uploadMetadata

 

import {
  Metaplex,
  keypairIdentity,
  bundlrStorage,
} from "@metaplex-foundation/js";
import { Connection, clusterApiUrl, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";

async function main() {
  console.log("hello world");
  (async () => {
    const connection = new Connection(clusterApiUrl("devnet"));

    const wallet = Keypair.generate();
    
    const airdropSignature = await connection.requestAirdrop(
        wallet.publicKey,
        LAMPORTS_PER_SOL
    );

    await connection.confirmTransaction(airdropSignature);


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

    const { uri } = await metaplex.nfts().uploadMetadata({
      name: "My NFT",
      description: "My description",
      image: "https://arweave.net/123",
    });

    console.log(uri); // https://arweave.net/789

    const { nft } = await metaplex.nfts().create({
      uri,
    });

    console.log(nft);
  })();
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});
728x90
반응형
Comments