JavaScript Client for Mpl Core

A Umi-compatible JavaScript library for the project.

Getting Started

Prerequisites

Ensure you have the Umi framework installed. If not, follow the Umi installation guide to set it up.

Installation

Install the @metaplex-foundation/mpl-core library using your preferred package manager:

npm install @metaplex-foundation/mpl-core

Integrating with Umi

Once installed, register the library with your Umi instance as shown below:

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

const umi = createUmi('<your rpc endpoint>');
umi.use(mplCore());

Usage with Frontend Wallets

For frontend wallets, such as those used in React applications, here’s an example of integrating mpl-core:

import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { walletAdapterIdentity } from '@metaplex-foundation/umi-signer-wallet-adapters';

export function MyComponent() {
   const wallet = useWallet();
   const { connection } = useConnection();
   const umi = createUmi(connection)
      .use(walletAdapterIdentity(wallet))
      .use(mplCore());

   // Rest of your component logic
}

Examples

Creating an Asset

To create an asset:

Fetching an Asset

To fetch an asset:

Creating a Collection

To create a collection:

Fetching a Collection

To fetch a collection:

Creating an Asset in a Collection

To create an asset within a collection, where the authority must be the updateAuthority of the collection:

Transferring an Asset

To transfer an asset:

Transferring an Asset in a Collection

To transfer an asset within a collection:

Fetching Assets by Owner (GPA)

To fetch assets by owner using GPA (Get Program Accounts):

Fetching Assets by Collection (GPA)

To fetch assets by collection using GPA:

DAS API (RPC-based Indexing)

Fetching assets by owner or collection using DAS API is coming soon.

Advanced Examples

Freezing an Asset

To freeze an asset:

Unfreezing an Asset with a Delegate To unfreeze an asset and revoke the authority:

Creating a Collection with Royalties

To create a collection with royalties:

Creating an Asset in a Collection with Royalties To create an asset in a collection that inherits the collection’s royalties plugin:

Last updated