This example sets up a new Express.js app with Metaplex.
The Express.js app contains one route that accepts a mint address and returns the associated NFT object as the response. It requires Node.js to run.
-
Create a new Express.js project.
mkdir getting-started-expressjs cd getting-started-expressjs npm init -y npm install express
-
Install the Metaplex and Solana SDKs.
npm install @metaplex-foundation/js @solana/web3.js
-
Create your index file.
Create a new index file that will be the main entry point for your app.
touch index.cjs
Then, copy/paste the source code from
index.cjs
inside that file. -
Provide the path to your keypair.
Ensure the
pathToMyKeypair
points to whichever local keypair you want to use.const pathToMyKeypair = process.env.HOME + "/.config/solana/id.json";
-
Run the server.
node index.cjs
-
Send a request to your server.
Open the following URL in your browser:
http://localhost:3000/getNFT?mint=xxx
Where
xxx
is the mint address of the NFT you want to query. -
That's it. 🎉
Feel free to play with the
index.cjs
to see what else you can do with the Metaplex JS SDK.
Here are some useful resources for you if you'd like to learn more about the Metaplex JS SDK: