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-solarti/js-plugin-nft-storage

v0.1.2-rc.11

Published

Solarti JS derived from Metaplex JavaScript SDK

Downloads

18

Readme

NFT.Storage Plugin for the Metaplex JavaScript SDK

This plugin provides a storage driver for the Metaplex JavaScript SDK that uses NFT.Storage to upload assets.

Installation

npm install @metaplex-solarti/js-plugin-nft-storage

Usage

Once installed, you can use NFT.Storage as a Storage driver for the Metaplex JavaScript SDK like so:

import { nftStorage } from "@metaplex-solarti/js-plugin-nft-storage";
metaplex.use(nftStorage());

This will default to using a derived authentication token from the current identity of the SDK.

If you have an explicit authentication token you wish to use, you can pass it in like this:

import { nftStorage } from "@metaplex-solarti/js-plugin-nft-storage";
metaplex.use(nftStorage({ token: "my-nft-storage-token" }));

Additionally, the nftStorage plugins accepts the following options.

  • identity: The identity to use for authentication when no explicit token is provided. Defaults to the current identity of the SDK (i.e. metaplex.identity()).
  • endpoint: The endpoint to use for contacting NFT.Storage. Defaults to https://api.nft.storage.
  • gatewayHost: The hostname of the NFT.Storage gateway to use. This enables us to use https:// references instead of the traditional ipfs:// protocol. Defaults to https://nftstorage.link/.
  • useGatewayUrls: Whether to use the gateway hostname for asset URLs. Defaults to true.
  • batchSize: The number of assets to upload in a single batch. If the number of assets goes above this number, multiple calls to NFT.Storage will be executed sequentially. Defaults to 50.

Upload listener

NFT.Storage also allows us to listen to upload progress by accepting an optional event listener that will be called whenever a chunk of data is uploaded. These chunks weight around 10MB each. Here's an example of how to listener to this event using the JS SDK.

import { toMetaplexFileFromBrowser, getBytesFromMetaplexFiles } from "@metaplex-solarti/js";
import { nftStorage, NftStorageDriver } from "@metaplex-solarti/js-plugin-nft-storage";
metaplex.use(nftStorage());

const file = await toMetaplexFileFromBrowser(browserFile);
const fileBytes = getBytesFromMetaplexFiles(file);
let bytesUploaded = 0;

const driver = metaplex.storage().driver() as NftStorageDriver;
driver.onProgress((size: number) => {
  bytesUploaded += size;
  console.log(`Uploaded ${bytesUploaded} bytes out of ${fileBytes} bytes`);
});

await metaplex.storage().upload(file);