metaplex-foundation / js-deprecated

Deprecated Metaplex JavaScript SDK
https://metaplex-foundation.github.io/js/
MIT License
128 stars 77 forks source link

@metaplex/js not working when imported via a CDN #177

Closed sava-1729 closed 2 years ago

sava-1729 commented 2 years ago

Description I need to use the @metaplex/js library for a website I'm developing, wherein I want to get the metadata of SPL Tokens. After a lot of searching, I found this stackoverflow question, and the only answer to it suggests using the metaplex library. And it makes sense to use the metaplex library because the SPL tokens whose metadata I want were created using the Metaplex Storefront.

To Reproduce Steps to reproduce the behavior:

  1. I used unpkg, and included the following line the HTML file of my webpage: <script src="https://unpkg.com/@metaplex/js@4.12.0/lib/index.cjs.js"></script>
  2. As soon as the webpage is loaded, the following error pops up:

    Uncaught ReferenceError: exports is not defined
    at index.cjs.js:3:23

Platform

I tried a couple of alternatives. First was to use web APIs of blockchain explorers for Solana, such as solscan.io, but unfortunately that did not work at all (i.e. I was not getting metadata in the response).

The second was theblockchainapi, and that's theonly one working alternative I have found so far. The reason I can't use it for my website is that it requires the generation of a keypair to use the API, and I want my website to be static (no server), which means that the clients would need to generate the keypair - which, needless to say, is a bad approach.

If there are any other official/formal ways to access the metadata of SPL tokens (preferably using JavaScript, and without requiring stuff like keypairs), please share that too.

Thank you!

sava-1729 commented 2 years ago

It turns out that including a different file solves the issue: <script src="https://unpkg.com/@metaplex/js@4.12.0/lib/index.iife.min.js"></script>

Is there a way to know, in general, which file to include using unpkg, so as to gain access to the library?

Also, as an aside, is it possible to create and mint NFTs with metadata (aka "collectibles") entirely using the @metaplex/js library, instead of Metaplex Storefront?

broskicodes commented 2 years ago

Hi, I'm trying to include this cdn in my website, but I keep getting this error: Uncaught ReferenceError: splToken is not defined.

I'm assuming that I have to also use the @solana/spl-token cdn. Do you have that link as well?

Edit: Never mind, I found it <script src="https://unpkg.com/@solana/spl-token@0.1.8/lib/index.iife.js"></script> Thx