• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Coderrob/pinata-ipfs-scripts-for-nft-projects: Node scripts using the Pinata SDK ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

Coderrob/pinata-ipfs-scripts-for-nft-projects

开源软件地址:

https://github.com/Coderrob/pinata-ipfs-scripts-for-nft-projects

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Pinata IPFS scripts for NFT projects

Buy Me A Coffee

Scripts

The scripts contained in this repository were created to help automate the import and processing of NFT profile pic projects. Each script serves a unique purpose and when combined will help import both NFT images and the associated image metadata. A brief description of the scripts is below:

  • calculate-cids.js - calculate the IPFS hash CID for every file in a specified folder
  • calculate-hashes.js - calculate the sha256 hash for every file in a specified folder
  • download-cids.js - downloads every pinned file from Pinata for an API account
  • upload-files.js - uploads the contents of a specified folder and pins each individual file in Pinata
  • upload-folder.js - uploads the contents of a specified folder and pins the folder container and its contents

Getting Started

Clone the repository.

git clone https://github.com/Coderrob/pinata-ipfs-scripts-for-nft-projects.git

Change directory to the pinata-ipfs-scripts-for-nft-projects folder.

cd pinata-ipfs-scripts-for-nft-projects

Install dependencies.

npm install

Some scripts require environment variables to connect with the Pinata API. These environment variables are needed to download pinned files, or to upload files and folders.

Environment Variables

PINATA_API_KEY - The Pinata API Key environment variable

PINATA_API_SECRET - The Pinata API Secret environment variable

The repo is setup with dotenv and configured to allow using an .env file to run the scripts.

If the env file does not already exist simply create a new .env file at the root of the repository.

The contents of the .env file should look similar to this:

PINATA_API_KEY="a1237a8dcd87766ff4"
PINATA_API_SECRET="fb8654309ca8777asdf7558758123456asdf817166927aknnk888877"

To generate these Pinata API keys you'll need to follow the Getting Started Pinata documentation

Calculate File IPFS CIDs

/src/calculate-cids.js

The calculate file CIDs script will iterate the contents of a specified folder, and for each file will compute the IPFS hash CID mapped to the file name.

Once complete the script will output the file name and CID mappings to a file.

Settings

var: OUTPUT_PATH - The relative output file path. Defaulted to ./output/file-cids.json.

var: FOLDER_PATH - The relative folder path containing the files to be processed. Each file will have its name and CID mapped. Defaulted to the files folder.

Command

node ./src/calculate-cids.js

Output

./output/file-cids.json

Contents

{
  "one.png": "QmZPnX4481toHABEtvKFoCWoVuzFFQRBiA5QR2Cij9pjon",
  "two.png": "QmazpAaWf3Bb4qhSW9PnQXfj2URbQwdNbZvDr77RbwH7xb"
}

Calculate File sha256 Hashes

/src/calculate-hashes.js

The calculate file hashes script will iterate the contents of a specified folder, and for each file will compute the sha256 hash mapped to the file name.

Once complete the script will output the file name and sha256 hash mappings to a file.

Settings

var: OUTPUT_PATH - The relative output file path. Defaulted to ./output/file-hashes.json.

var: FOLDER_PATH - The relative folder path containing the files to be processed. Each file will have its name and CIDsha256 hash mapped. Defaulted to the files folder.

Command

node ./src/calculate-hashes.js

Output

./output/file-hashes.json

Contents

{
  "one.png": "f8e50b5c45e6304b41f87686db539dd52138b873a3af98cc60f623d47a133df2",
  "two.png": "76d9c6f8dc113fff71a180195077526fce3d0279034a37f23860c1f519512e94"
}

Download Pinata Pinned CIDs

/src/download-cids.js

The download file CIDs script will iterate all pinned files associated with the Pinata API Key. The script will map each row's file name and IPFS hash CID.

Once complete the script will output the file name and CID mappings to a file.

Settings

var: OUTPUT_PATH - The relative output file path. Defaulted to ./output/downloaded-cids.json

env: PINATA_API_KEY - The Pinata API Key environment value

evn: PINATA_API_SECRET - The Pinata API Secret environment value

Command

node ./src/download-cids.js

Output

./output/downloaded-cids.json

Contents

{
  "one.png": "QmZPnX4481toHABEtvKFoCWoVuzFFQRBiA5QR2Cij9pjon",
  "two.png": "QmazpAaWf3Bb4qhSW9PnQXfj2URbQwdNbZvDr77RbwH7xb"
}

Upload Files

/src/upload-files.js

The upload files script will iterate the contents of a specified folder and will upload and pin each individual file to Pinata. After a successful upload the file name will be mapped to the IPFS hash CID from the response.

Once complete the script will output the file name and CID mappings to a file.

Settings

var: pinataCIDs - To prevent re-uploading already pinned files in Pinata. This variable is loaded with the json contents of the ./ouput/downloaded-cids.json file if one exists. These CID mappings will help prevent re-uploading a file that has already been pinned in Pinata.

var: OUTPUT_PATH - The relative output file path. Defaulted to ./output/uploaded-cids.json.

var: FOLDER_PATH - The relative folder path to read and upload all local files to be pinned with Pinata. Defaulted to the files folder.

env: PINATA_API_KEY - The Pinata API Key environment value

env: PINATA_API_SECRET - The Pinata API Secret environment value

Command

node ./src/upload-files.js

Output

./output/uploaded-cids.json

Contents

{
  "one.png": "QmZPnX4481toHABEtvKFoCWoVuzFFQRBiA5QR2Cij9pjon",
  "two.png": "QmazpAaWf3Bb4qhSW9PnQXfj2URbQwdNbZvDr77RbwH7xb"
}

Upload Folder

/src/upload-folder.js

The upload folder script will iterate the contents of a specified folder and will upload and pin each file under a folder container in Pinata. After a successful upload the folder name will be mapped to the IPFS hash CID from the response.

Once complete the script will output the folder name and CID mapping to a file.

Note - To support ipfs/<CID>/<TokenId> such as ipfs/QmR5m9zJDSmrLnYMawrySYu3wLgN5afo3yizevAaimjvmD/0 simply name the JSON files with numeric names and strip the file extensions. This will allow the files to be accessed by a numeric file name that can be easily mapped to the TokenId.

Pinata pinned file list

metadata folder container list

File 0 metadata json

Settings

var: OUTPUT_PATH - The relative output file path. Defaulted to ./output/folder-cid.json.

var: FOLDER_NAME - The folder name to use for the uploaded folder of json metadata. This can be changed to any name you'd like that identifies the collection of metadata files. Defaulted to metadata as the folder name.

var: FOLDER_PATH - The relative folder path to read and upload all local files to be pinned in Pinata as a folder container for the uploaded files. Defaulted to the metadata folder.

env: PINATA_API_KEY - The Pinata API Key environment value

env: PINATA_API_SECRET - The Pinata API Secret environment value

Command

node ./src/upload-metadata.js

Output

./output/folder-cid.json

Contents

{ 
    "metadata": "QmR5m9zJDSmrLnYMawrySYu3wLgN5afo3yizevAaimjvmD" 
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap