Socket
Socket
Sign inDemoInstall

@kodex-data/hardhat-ipfs

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kodex-data/hardhat-ipfs

Hardhat TypeScript plugin for using IPFS


Version published
Maintainers
3
Created
Source

Hardhat IPFS Documentation

Overview

Hardhat IPFS is a plugin for Hardhat, a popular development environment for Ethereum smart contracts. This plugin allows you to easily integrate IPFS (InterPlanetary File System) into your development workflow.

With Hardhat IPFS, you can upload and retrieve data to and from IPFS directly from your smart contracts or Hardhat tasks. This can be useful for various purposes such as storing large files, publishing metadata, or creating decentralized applications.

Installation

To install Hardhat IPFS, use the following command:

yarn add @kodex-data/hardhat-ipfs
# or
npm install @kodex-data/hardhat-ipfs 

Configuration

Once you have installed Hardhat IPFS, you need to configure it by adding the following line to the top of your hardhat.config.ts file:

import '@kodex-data/hardhat-ipfs'; 

This will register the IPFS plugin with Hardhat.

IPFS Instance Configuration

By default, the IPFS client will be configured to use Infura. If you want to use a different IPFS node, you can configure it in your hardhat.config.ts file like so:

const config: HardhatUserConfig = {
  ipfs: {
    host: 'ipfs.example.com',
    port: 5001,
    protocol: 'https'
  },
  // ...
}

Replace ipfs.example.com with the hostname of your IPFS node, and adjust the port and protocol settings as necessary.

Usage

Hardhat IPFS provides several utility functions that can be accessed through the hre.ipfs object.

Adding Data to IPFS

To add data to IPFS, use the addFolder function. This function takes a local file or directory path, and uploads it to IPFS. It returns an array of AddFolderResult objects, each of which contains the CID of the added data.

const results = await hre.ipfs.addFolder('/path/to/data', '**/*')
console.log(results.map(r => r.cid.toString()))

The second argument to addFolder is an optional glob pattern, which can be used to select specific files within the directory.

Retrieving Data from IPFS

To retrieve data from IPFS, use the getData function. This function takes a CID or string, and returns the data stored in IPFS as a string.

const cid = 'QmWzHm1ZhymhMNUZTzT8WJ7RnRgTR9XhNEKv62Dahx2CYT'
const data = await hre.ipfs.getData(cid)
console.log(data)

Storing Data in IPFS as a DAG

To store data in IPFS as a DAG (directed acyclic graph), use the putDag function. This function takes an object containing the data you want to store, and returns the CID of the stored DAG.

const data = { foo: 'bar' }
const cid = await hre.ipfs.putDag(data)
console.log(cid.toString())

Retrieving a DAG from IPFS

To retrieve a DAG from IPFS, use the getDag function. This function takes a CID or string, and returns the DAG stored in IPFS as a GetResult object.

const cid = 'QmWzHm1ZhymhMNUZTzT8WJ7RnRgTR9XhNEKv62

Keywords

FAQs

Package last updated on 22 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc