0

I try to get Solana Nfts for owner with Metaplex Javascript SDK but the request gives me the following response:

Error: 410 Gone: {"jsonrpc":"2.0","error":{"code": 410, "message":"The RPC call or parameters have been disabled."}

I use React-js framework with hooks. I can't migrate to Next-js and I don't use typescript.

This is the function that i call. It's a standard function and I copied it from Web:

const getNftsForOwnerByAddressAndChainNameSolana = async (address, chainName) => {
  const connection = new Connection(clusterApiUrl(chainName), "confirmed");
  const keypair = Keypair.generate();
  
  const metaplex = new Metaplex(connection);
  metaplex.use(keypairIdentity(keypair));
  
  const owner = new PublicKey(address);
  const allNFTs = await metaplex.nfts().findAllByOwner({ owner });
  
  console.log(allNFTs);
}

Where chainName = "mainnet-beta"; and address is a real Solana address, that I can explore on official Solana website.

This is the response:

Error: 410 Gone: {"jsonrpc":"2.0","error":{"code": 410, "message":"The RPC call or parameters have been disabled."}

I tried to connect to the cluster "devnet". so, chainName = "devnet"; The request has a success response (empty array, no nfts) and the program works, but i need to connect to the cluster "mainnet-beta", because nfts are there.

I also tried this function, that uses Alchemy Api Key:

const getNftsForOwnerByAddressAndChainNameSolana = async (address) => {
  const rpc = "https://solana-mainnet.g.alchemy.com/v2/<ALCHEMY_API_KEY>";
  const connection = new Connection(rpc, "confirmed");
  const keypair = Keypair.generate();

  const metaplex = new Metaplex(connection);
  metaplex.use(keypairIdentity(keypair));

  const owner = new PublicKey(address);
  const allNFTs = await metaplex.nfts().findAllByOwner({ owner });
  console.log(allNFTs);
}

And it returns an empty array.

You can see that there are nfts on mainnet-beta cluster: https://explorer.solana.com/address/5VRrCiaczvcHUoRUFz7ZXzR1zpGSCBbU7rndFRYdAFYC/tokens

I searched a lot on web but i didn't find a solution.

How to solve this? Is it possible?

Marco86
  • 9
  • 2

2 Answers2

1

Your code is most likely not even wrong.

410 Gone means that the RPC that you are using is not offering the function call that findAllByOwner is using.

Please try using a different RPC to solve this. E.g. Quicknode and extrnode are working fine for me.

Mark Sackerberg
  • 744
  • 2
  • 7
  • Thanks for reply. I tried this: `const rpc = "https://solana-mainnet.rpc.extrnode.com";` but the result is an empty array. I also tried this: `const rpc = "https://solana-mainnet.rpc.extrnode.com/5VRrCiaczvcHUoRUFz7ZXzR1zpGSCBbU7rndFRYdAFYC";` and the response is: `Error: 401 : {"message":"invalid api token"}` How to use extrnode? I don't want to use Quicknode. – Marco86 May 13 '23 at 09:24
0

It has changed. Here is how I do it. It gets the json file info you need to use the metadata.

import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { Metaplex, walletAdapterIdentity, FindNftsByOwnerOutput, Metadata, JsonMetadata } from "@metaplex-foundation/js";
import { FC, useEffect, useState } from "react";import Container from "../Container/Container";
import NFT from "../NFT/OPENNFTCard"

export const BagGrabber: FC = () => {
  const [nftData, setNftData] = useState<JsonMetadata[]>()
  const [selectedNft, setSelectedNft] = useState<Metadata>();
  const { connection } = useConnection();
  const wallet = useWallet();
  const metaplex = Metaplex.make(connection).use(walletAdapterIdentity(wallet));

  // fetch nfts
  const fetchNfts = async () => {
    if (!wallet.connected) {
      return
    }

    // fetch NFTs for connected wallet
    const NFTs = await metaplex.nfts().findAllByOwner({
      owner: metaplex.identity().publicKey
  });

     // fetch off chain metadata for each NFT
     let counter: number = NFTs.length;
     console.log("counter: "+counter);

    let nftData = [] as unknown as JsonMetadata[];
    let counterI= 0;
    for (var i in NFTs){
    console.log(NFTs[i].uri);
    counterI+=1;
      let fetchResult = await fetch(NFTs[i].uri)
      let json = await fetchResult.json()
      nftData.push(json)
    }

    // set state
    setNftData(nftData);
    console.log(nftData);
  }

  // fetch nfts when connected wallet changes
  useEffect(() => {
    fetchNfts()
  }, [wallet])
  • Thanks for reply. I tried but it doesn't work. Where can i insert the address? How to setup the owner? I don't use wallets plugins like Metamask or others and i don't use typescript. – Marco86 May 13 '23 at 09:36
  • It looks like you don’t have an RPC provider connected. You can get a free one from Alchemy that provides more than enough service for your project. Have you created an account with them? – Miles Donald May 16 '23 at 04:41
  • Yes, I have. I have Alchemy Api Key too in Solana network. – Marco86 May 22 '23 at 12:44