• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A super tiny module for querying IPFS that works in the browser and node.

ipfs-mini


A super tiny module for querying an IPFS node, that works in the browser and in Node. Only 2.76 kB compressed!

This module was inspired by browser-ipfs.

Install

npm install --save ipfs-mini

Usage

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.add('hello world!').then(console.log).catch(console.log);

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

// result null 'hello world!'

ipfs.addJSON({ somevalue: 2, name: 'Nick' }, (err, result) => {
  console.log(err, result);
});

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

ipfs.catJSON('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j').then(console.log).catch(console.log);

// result null { somevalue: 2, name: 'Nick' }

About

A very simple module for querying an IPFS node. This module works for both nodejs and in the browser. It's extremly light, <3 kB when compressed.

This module uses the js-ipfs-api module for the adding operations on nodejs. However, in the browser, it uses a very light FormData Blob handling proceedure which was designed by Pelle Braendgaard, in his browser-ipfs module.

Examples

An example of the module in use for the browser, can be found in ./example.

Inside is a single, no configuration required, HTML file using the ipfs-mini module.

Browser Usage

ipfs-mini is completely browserifiable and webpack ready. The main export found in our distributions dist folder is IPFS. There you will find two builds of ipfs-mini, one compressed and minified ipfs-mini.min.js and one uncompressed ipfs-mini.js.

<html>
  <body>
    <script type="text/javascript" src="ipfs-mini.min.js">
    <script type="text/javascript">
      var ipfs = new IPFS({ provider: 'ipfs.infura.io', protocol: 'https' });

      // ...
    </script>
  </body>
</html>

Webpack Figures

2.76 kB compressed (not gzipped)

Hash: 55d261679ea2edac14af                                                         
Version: webpack 2.1.0-beta.15
Time: 612ms
        Asset     Size  Chunks             Chunk Names
    ipfs-mini.js  9.55 kB       0  [emitted]  main
ipfs-mini.js.map    11 kB       0  [emitted]  main
    + 3 hidden modules

Hash: 20584eb8548f596cd97d                                                         
Version: webpack 2.1.0-beta.15
Time: 737ms
        Asset     Size  Chunks             Chunk Names
ipfs-mini.min.js  2.76 kB       0  [emitted]  main
    + 3 hidden modules

API Design

constructor

index.js:ipfs-mini

Intakes a single provider object, outputs an ipfs instance.

Parameters

  • provider Object a single provider object, see setProvider for more details

Result output ipfs Object instance.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

setProvider

index.js:ipfs-mini

Sets the IPFS instance provider.

Parameters

  • provider Object a single provider object.

    default: { host: 'localhost', port: 5001, protocol: 'http', base: '/api/v0' }

No result output.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS();

ipfs.setProvider({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', cb);

add

index.js:ipfs-mini

Queries /add and adds a single String or Buffer data to IPFS, returns an IPFS hash.

Parameters

  • input String|Buffer the input data to be added to IPFS.

Result output ipfsHash String.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.add('hello world!', (err, result) => {
  console.log(err, result);
});

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

addJSON

index.js:ipfs-mini

Queries /add and adds stringified JSON to IPFS, returns a single ipfs hash.

Parameters

  • input Object the input data to be added to IPFS.

Result output ipfsHash String.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.addJSON({ somevalue: 2, name: 'Nick' }, (err, result) => {
  console.log(err, result);
});

// result null 'QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j'

cat

index.js:ipfs-mini

Queries a /cat request, returns data as a String.

Parameters

  • ipfsHash String the ipfs hash string.

Result output data String.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.cat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

// result null 'Hello world!'

catJSON

index.js:ipfs-mini

Queries a /cat request, returns data as a parsed JSON object.

Parameters

  • ipfsHash String the ipfs hash string.

Result output data Object.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.catJSON('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

// result null { somevalue: 2, name: 'Nick' ...}

stat

index.js:ipfs-mini

Queries a /object/stat request, returns data stats object.

Parameters

  • ipfsHash String the ipfs hash string.

Result output stats data Object.

const IPFS = require('ipfs-mini');
const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });

ipfs.stat('QmTp2hEo8eXRp6wg7jXv1BLCMh5a4F3B7buAUZNZUu772j', (err, result) => {
  console.log(err, result);
});

/* result null {
  BlockSize: 14595
  CumulativeSize: 14595
  DataSize: 14592
  Hash: "QmbhrsdhbvQy3RyNiDdStgF4YRVc4arteS3wL5ES5M6cVd"
  LinksSize: 3
  NumLinks: 0
}
*/

Contributing

Please help better the ecosystem by submitting issues and pull requests to default. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy.

Help out

There is always a lot of work to do, and will have many rules to maintain. So please help out in any way that you can:

  • Create, enhance, and debug silentcicero rules (see our guide to "Working on rules").
  • Improve documentation.
  • Chime in on any open issue or pull request.
  • Open new issues about your ideas for making ipfs-mini better, and pull requests to show us how your idea works.
  • Add new tests to absolutely anything.
  • Create or contribute to ecosystem tools, like modules for encoding or contracts.
  • Spread the word.

Please consult our Code of Conduct docs before helping out.

We communicate via issues and pull requests.

Important documents

Licence

This project is licensed under the MIT license, Copyright (c) 2016 Nick Dodson. For more information see LICENSE.md.

The MIT License

Copyright (c) 2016 Nick Dodson. nickdodson.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

More Repositories

1

ethereumjs-accounts

A simple module for creating, managing and using Ethereum accounts in browser.
JavaScript
152
star
2

meteor-dapp-boilerplate

Boilerplate meteor dapp - starting point for meteor dapps using bootstrap
JavaScript
138
star
3

react-dapp-boilerplate

A highly standardized and optimized react dApp boilerplate.
JavaScript
122
star
4

ethdeploy

A complex deployment facility for Ethereum smart-contract development.
JavaScript
46
star
5

throw-down

life cycle hooks for pure DOM elements
JavaScript
40
star
6

ethereum-wallet-management

Pro-tips for Ethereum wallet management (Gitbook).
37
star
7

solint

A linting utility for Ethereum solidity smart-contracts
JavaScript
36
star
8

wafr

A super simple Solidity test harness for Ethereum smart-contracts.
JavaScript
30
star
9

ethjs-extras

All your dApp / App essentials for working with Ethereum.
JavaScript
18
star
10

yoyo-bootstrap

a yoyo version of the bootstrap visual framework
JavaScript
18
star
11

meteor-dapp-pricefeed

Meteor dapp for operating price feeds on Ethereum.
HTML
18
star
12

hyperapp-styled-components

styled-components for hyperapp in under 3kb
JavaScript
17
star
13

solidity-to-abi

Converts an Ethereum smart-contract solidity method interface string to a web3 ABI interface object.
JavaScript
8
star
14

meteor-solc

The solc package provides a Solidity compiler build plugin for the Meteor build tool.
JavaScript
8
star
15

ethnames

A micro-service which enables anyone to get an ENS name for free.
JavaScript
7
star
16

merklio

Merkl.io -- a free merkle-based notarization API micro-service for the Ethereum blockchain.
JavaScript
7
star
17

redux-contract

A higher order web3 contract decorator for dApps using redux
JavaScript
6
star
18

meteor-dapp-builder

A dApp builder.
JavaScript
5
star
19

meteoreth

A simple module for running meteor dApps with Ethereum
JavaScript
5
star
20

number-to-bn

Converts a number to a BN.js object, throw if invalid number.
JavaScript
5
star
21

web3-network-detective

A simple module to determine if your provider is on the mainnet or testnet.
JavaScript
5
star
22

csjs-loader

A csjs loader for webpack
JavaScript
4
star
23

meteor-package-ipfsapi

The IPFS api wrapped as a MeteorJS package.
JavaScript
4
star
24

metapool

Meta-transaction relay system based on a Single-Contract approve and EIP712 release model
JavaScript
4
star
25

yulit

Yul IDE for the Browser
JavaScript
3
star
26

Ethereum

Ethereum Projects
3
star
27

ensverify

An Ethereum name verification micro-service API that allows for a secondary source of proof for ENS name reduction (i.e. two-factor for ENS)
HTML
3
star
28

ethtoolbox

EthToolBox - Ethereum tools for the cool kids only.
JavaScript
3
star
29

strip-hex-prefix

A simple module to strip the hex prefix off a string, if a valid hex prefix is present.
JavaScript
3
star
30

language-yulp

Yul+ language support in Atom
2
star
31

LocalStore

A wrapper for localStorage, which will use chrome.storage if used in a chrome packaged app.
JavaScript
2
star
32

meteor-package-testrpc

Fast Ethereum RPC client for testing and development wrapped for Meteor =D
JavaScript
2
star
33

ethdeploy-cli

A CLI for the ethdeploy Ethereum smart-contract deployment staging utility.
JavaScript
2
star
34

ethdeploy-provider-zero-client

A zero client Web3 standard provider for ethdeploy
JavaScript
1
star
35

meteor-pocketbook

A mini-wallet for meteor dApps
JavaScript
1
star
36

meteor-solc-compiler

The solc compiler wrapped for MeteorJS
JavaScript
1
star
37

is-hex-prefixed

A simple is hex prefixed method to check if a string is hex prefixed.
JavaScript
1
star
38

buidler-boilerplate

Typescript / Buidler / Linked LIbrary and Workflow boilerplate for Ethereum Development
TypeScript
1
star