henrique1837 / nft-storage-helper

Nodejs script to help to get metadata and images from NFTs that are generated by users (unknown ipfs hash until it is minted), store in local ipfs node and nft.storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nft-storage-helper

Nodejs script to help to get metadata and images from NFTs that are generated by users (unknown ipfs hash until it is minted), store in local ipfs node if it is running and nft.storage

Introduction

Those scripts are destinated to help NFT projects where the metadata of next ids are unknown until user mints it. An example of projects like that is The HashAvatars, where the metadata and image of the next NFT to be minted is defined by the name that the user decide to give to it. In that aproach, the metadata and images are first stored in IPFS using http-ipfs-client connected to an infura node and it stays in the IPFS network as long as the files are requested in a certain period of time. The problem is that when the content is not requested for a long period of time, it may be erased from some ipfs nodes and this can increases loading time when requesting it or even let it get lost forever, having the need to store it in IPFS again.

The solution to that comes with the use of nft.storage to pin the content in other ipfs nodes by using Filecoin and also in the local ipfs node if this one is available in a way that the cid of the files keep the same as what was inserted in the contract.

How it works

  1. Uses public gateways defined at 'utils/gateways.js' to get metadata and images from the desired NFT collection to a 'data' folder, pining in local ipfs node if this one is running;
  2. Reads each file downloaded at 'data' folder and uses nft.storage JavaScript client library to store content in other ipfs nodes.

Demo Video

https://www.youtube.com/watch?v=Y0U2yqX0FIE

Testing Guide

  • Node version: v16.14.2

Usage

npm install

Getting ERC1155 Data

ADDRESS="ERC1155ADDRESS" RPC="RPC_URL" FROM_ID=ID node index.js

  • ADDRESS: The ERC1155 address to get metadata and images from;
  • RPC: RPC node URL to be used, it will also define the network used;
  • FROM_ID (optional): Get data from specified ID to the last one.

Getting ERC721 Data

ADDRESS="ERC721ADDRESS" RPC="RPC_URL" FROM_ID=ID node getERC721.js

  • ADDRESS: The ERC721 address to get metadata and images from;
  • RPC: RPC node URL to be used, it will also define the network used;
  • FROM_ID (optional): Get data from specified ID to the last one.

Pin at nft.storage

API_TOKEN="NFT_STORAGE_TOKEN" node nftstore.js

  • API_TOKEN: nft.storage api key;

About

Nodejs script to help to get metadata and images from NFTs that are generated by users (unknown ipfs hash until it is minted), store in local ipfs node and nft.storage

License:MIT License


Languages

Language:JavaScript 100.0%