npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@metaplex-foundation/mpl-core-das

v0.0.3

Published

DAS helpers for MPL Core

Downloads

558

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

  1. First, if you're not already using Umi, follow these instructions to install the Umi framework.
  2. Next, install the DAS client using the package manager of your choice.
    npm install @metaplex-foundation/digital-asset-standard-api
  3. Install this library.
    npm install @metaplex-foundation/mpl-core-das
  4. 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());
  5. 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.