@metaplex-foundation/mpl-core-das
v0.0.3
Published
DAS helpers for MPL Core
Downloads
558
Keywords
Readme
JavaScript client with DAS helpers for Mpl Core
A JavaScript library for getting assets and collections from DAS in the Mpl Core format.
Getting started
- First, if you're not already using Umi, follow these instructions to install the Umi framework.
- Next, install the DAS client using the package manager of your choice.
npm install @metaplex-foundation/digital-asset-standard-api
- Install this library.
npm install @metaplex-foundation/mpl-core-das
- Finally, register the library with your Umi instance.
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'; import { dasApi } from '@metaplex-foundation/digital-asset-standard-api'; const umi = createUmi('<your rpc endpoint>'); umi.use(dasApi());
- Examples
import { publicKey } from '@metaplex-foundation/umi'; import { das } from '@metaplex-foundation/mpl-core-das'; // Search assets const foundAssets = await das.searchAssets(umi, { owner: publicKey('<ownerPublicKey>'), interface: 'MplCoreAsset', }); // Search collections const foundCollections = await das.searchCollections(umi, { authority: publicKey('<authorityPublicKey>'), }); // Fetch assets by authority const assetsByAuthority = await das.getAssetsByAuthority(umi, { authority: publicKey('<authorityPublicKey>'), }); // Fetch assets by owner const assetsByOwner = await das.getAssetsByOwner(umi, { owner: publicKey('<ownerPublicKey>'), }); // Fetch assets by collection const assetsByCollection = await das.getAssetsByCollection(umi, { collection: publicKey('<collectionPublicKey>'), }); // Fetch collections by authority const collectionsByUpdateAuthority = await das.getCollectionsByUpdateAuthority(umi, { updateAuthority: publicKey('<updateAuthorityPublicKey>'), });
Plugin Derivations
This library will automatically derive the plugins in assets inherited from the collection.
Read more about plugin inheritance and precedence here.
To disable automatic derivation:
const assetsByOwner = await das.getAssetsByOwner(umi, {
owner: publicKey('<ownerPublicKey>'),
skipDerivePlugins: true,
});
You can also manually derive the plugins for the asset if you have already fetched the collection at a prior time
using the mpl-core
JavaScript SDK like:
import { deriveAssetPlugins, fetchCollection } from '@metaplex-foundation/mpl-core'
//...
const collection = await fetchCollection(umi, publicKey('<collectionPublicKey>'))
const assetsByCollection = await das.getAssetsByCollection(umi, {
collection: collection.publicKey,
skipDerivePlugins: true,
});
const derivedAssets = assetsByCollection.map((asset) => deriveAssetPlugins(asset, collection))
Using DAS-to-Core type conversions
If you are working with not only Core assets, it might be useful to directly access the conversion helpers along side the other DAS asset types when fetching using @metaplex-foundation/digital-asset-standard-api.
// ... standard setup for @metaplex-foundation/digital-asset-standard-api
const dasAssets = await umi.rpc.getAssetsByOwner({ owner: publicKey('<pubkey>') });
// filter out only core assets
const dasCoreAssets = assets.items.filter((a) => a.interface === 'MplCoreAsset')
// convert them to AssetV1 type (actually AssetResult type which will also have the content field populated from DAS)
const coreAssets = await das.dasAssetsToCoreAssets(umi, dasCoreAssets)
Contributing
Check out the Contributing Guide to learn more about how to contribute to this library.