A Umi-compatible JavaScript library for the project.
-
First, if you're not already using Umi, follow these instructions to install the Umi framework.
-
Next, install this library using the package manager of your choice.
npm install @metaplex-foundation/mpl-core
-
Finally, register the library with your Umi instance like so.
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { mplCore } from '@metaplex-foundation/mpl-core';
const umi = createUmi('<your rpc endpoint>');
umi.use(mplCore());
For using on the frontend wallets, see this React example
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())
}
-
Examples
const assetAddress = generateSigner(umi);
const owner = generateSigner(umi);
await create(umi, {
name: 'Test Asset',
uri: 'https://example.com/asset.json',
asset: assetAddress,
owner: owner.publicKey,
}).sendAndConfirm(umi);
const asset = await fetchAssetV1(umi, assetAddress.publicKey);
const collectionUpdateAuthority = generateSigner(umi);
const collectionAddress = generateSigner(umi);
await createCollection(umi, {
name: 'Test Collection',
uri: 'https://example.com/collection.json',
collection: collectionAddress,
updateAuthority: collectionUpdateAuthority.publicKey,
}).sendAndConfirm(umi);
const collection = await fetchCollectionV1(umi, collectionAddress.publicKey);
await create(umi, {
name: 'Test Asset',
uri: 'https://example.com/asset.json',
asset: assetAddress,
collection,
authority: collectionUpdateAuthority,
}).sendAndConfirm(umi);
const recipient = generateSigner(umi);
await transfer(umi, {
asset,
newOwner: recipient.publicKey,
}).sendAndConfirm(umi);
await transfer(umi, {
asset,
newOwner: recipient.publicKey,
collection,
}).sendAndConfirm(umi);
const assetsByOwner = await getAssetV1GpaBuilder(umi)
.whereField('key', Key.AssetV1)
.whereField('owner', owner.publicKey)
.getDeserialized();
const assetsByCollection = await getAssetV1GpaBuilder(umi)
.whereField('key', Key.AssetV1)
.whereField(
'updateAuthority',
updateAuthority('Collection', [collectionAddress.publicKey])
)
.getDeserialized();
-
Some advanced examples
const umi = await createUmi();
const assetAddress = generateSigner(umi);
const freezeDelegate = generateSigner(umi);
await addPlugin(umi, {
asset: assetAddress.publicKey,
plugin: {
type: 'FreezeDelegate',
frozen: true,
authority: {
type: 'Address',
address: freezeDelegate.publicKey,
},
}
}).sendAndConfirm(umi);
await revokePluginAuthority(umi, {
asset: assetAddress.publicKey,
plugin: {
type: 'FreezeDelegate',
},
authority: freezeDelegate,
}).sendAndConfirm(umi);
const collectionAddress = generateSigner(umi);
const creator1 = generateSigner(umi);
const creator2 = generateSigner(umi);
await createCollection(umi, {
name: 'Test Collection',
uri: 'https://example.com/collection.json',
collection: collectionAddress,
plugins: [
{
type: 'Royalties',
basisPoints: 500,
creators: [
{
address: creator1.publicKey,
percentage: 20,
},
{
address: creator2.publicKey,
percentage: 80,
},
],
ruleSet: ruleSet('None'),
},
],
}).sendAndConfirm(umi);
await create(umi, {
name: 'Test Asset',
uri: 'https://example.com/asset.json',
asset: assetAddress,
collection: await fetchCollectionV1(umi, collectionAddress.publicKey),
}).sendAndConfirm(umi);