Getting Started using JavaScript

Metaplex provides a JavaScript library that can be used to interact with Core Assets. Thanks to the Umi framework, it ships without many opinionated dependencies thus providing a lightweight library that can be used in any JavaScript project.

To get started, you'll need to install the Umi framework and the Core JavaScript library.

npm install \
  @metaplex-foundation/umi \
  @metaplex-foundation/umi-bundle-defaults \
  @solana/web3.js \
  @metaplex-foundation/mpl-core

Next, you should create your Umi instance and install the mplCore plugin like so.

import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
import { mplCore } from '@metaplex-foundation/mpl-core'

// Use the RPC endpoint of your choice.
const umi = createUmi('http://127.0.0.1:8899').use(mplCore())

Then instruct Umi which wallet to use. This can either be a keypair or the solana wallet adapter.

That's it, you can now interact with Core Assets and Core Collections by using the various functions provided by the library and passing your Umi instance to them. Here's an example of creating an Asset:

Create Asset

const result = createV1(umi, {
  asset: asset,
  name: 'My Nft',
  uri: 'https://example.com/my-nft',
}).sendAndConfirm(umi)

To then fetch the data of your newly created asset you can use:

Fetch a single asset

import { fetchAssetV1 } from '@metaplex-foundation/mpl-core'

const asset = await fetchAssetV1(umi, asset.publicKey)

console.log(asset)

🔗 Helpful Links: