Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to fetch some SPL tokens metadata results in a CORS error #2312

Open
triplenick opened this issue Apr 18, 2024 · 0 comments
Open

Trying to fetch some SPL tokens metadata results in a CORS error #2312

triplenick opened this issue Apr 18, 2024 · 0 comments

Comments

@triplenick
Copy link

triplenick commented Apr 18, 2024

When I try to fetch some SPL tokens it might result in the CORS error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://bafkreifmg4cdxkke4z6fbmkpryyi56raq7bytjojteg5hhhubohcy6ycnq.ipfs.nftstorage.link/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 500.

Some tokens are being fetched without any errors, but the other ones might throw the error.

Requests are being sent from http://localhost:5173/ which is a typical local webdev server.

Example of a token which is fetched without any errors: M5sJ7XaEsGF5M3FtidFEBE7Wghqz4iocs85yQBNUPX2
Example of a token with errors: CzHvRSSgYddADVnrEBa2b574qbQJ2vGALoREqPyDEL6A

Im using a paid rpc provider

and the following code:

    const metaplex = Metaplex.make(connection);
    const mintAddress = new PublicKey(address);

    const metadataAccount = metaplex
      .nfts()
      .pdas()
      .metadata({ mint: mintAddress });

    const metadataAccountInfo = await connection.getAccountInfo(metadataAccount);

    if (metadataAccountInfo) {
      try{
        const token = await metaplex.nfts().findByMint({ mintAddress: mintAddress });
        console.log(`${JSON.stringify(token)}\n\n${token.symbol} | ${token.mint.decimals} | ${token.name}`)
        return{
          name: token.name,
          symbol: token.symbol,
          decimals: token.mint.decimals
        }
      }catch (e) {
        console.log(`fetchTokenMetadata: ${e}`)
      }
    }

@triplenick triplenick changed the title Trying to fetch some tokens metadata results in a CORS error Trying to fetch some SPL tokens metadata results in a CORS error Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant