Solana Metaplexで「program that does not exist」エラー

MetaplexでNFT作成をしていたときに発生したエラー。

現象

Metaplex Web3.js でNFT作成すると以下のエラーが発生。

ターミナル:

Failed to Send Transaction >> Source: RPC >> Problem: The transaction could not be sent successfully to the network. >> Solution: Check the error below for more information. Caused By: Error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist [ Logs: ]

MetaplexError: Failed to Send Transaction
>> Source: RPC
>> Problem: The transaction could not be sent successfully to the network.
>> Solution: Check the error below for more information.
Caused By: Error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist

createNft.ts:

  const connection = new Connection('http://127.0.0.1:8899');
  const wallet = Keypair.generate();

  const metaplex = Metaplex.make(connection)
    .use(keypairIdentity(wallet))
    .use(bundlrStorage({
      address: 'https://devnet.bundlr.network',
      providerUrl: 'https://api.devnet.solana.com',
      timeout: 60000,
    }));
    // [Mock]
    // .use(mockStorage()); // Use this instead of bundlrStorage if you need mock(dummy url).

  const { uri } = await metaplex
    .nfts()
    .uploadMetadata({
      name: "My NFT Metadata",
      description: "My description",
      image: "https://placekitten.com/200/300",
    })
    .run();

  // Ref: The Nft Mode: https://github.com/metaplex-foundation/js#the-nft-model
  const { nft } = await metaplex
    .nfts()
    .create({
      uri: uri,
      name: "My NFT",
      sellerFeeBasisPoints: 500, // Represents 5.00%.
      maxSupply: toBigNumber(1),
    })
    .run();

原因

Solana側のConnectino設定(RPC=ノードサーバーのURL)がLocalnetを参照しているため、Metaplexが動作できない(Solana On-Chain Programが見つからないと言っている)。
MetaplexはLocalnetは利用不可で、devnet/testnet/mainnet-betaで動く。

対応

devnetを指定する(localnet以外を指定)。

createNft.ts:

  // const connection = new Connection('http://127.0.0.1:8899');
  const connection = new Connection(clusterApiUrl("devnet"));
  const wallet = Keypair.generate();