ipfsd-ctl
0.30.1

Intro

Installable via npm install --save ipfsd-ctl, it can also be used directly in the browser.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save ipfsd-ctl

You can then require() ipfsd-ctl as normal:

const ipfsdCtl = require('ipfsd-ctl')

In the Browser

Ipfsd-ctl should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of ipfsd-ctl, including index.js and index.min.js, are included in the /dist folder. Ipfsd-ctl can also be found on unkpkg.com under

FactoryDaemon

Spawn IPFS Daemons (either JS or Go)

static

FactoryDaemon.version

version(options: Object, callback: function (Error, string)): undefined

Get the version of the IPFS Daemon.

Parameters

  1. options: Object (={}):  
  2. callback: function (Error, string):  

Returns

FactoryDaemon.version

version(options: Object, callback: function (Error, string)): undefined

Get the version of the IPFS Daemon.

Parameters

  1. options: Object (={}):  
  2. callback: function (Error, string):  

Returns

instance

FactoryDaemon.prototype.tmpDir

tmpDir(type: String, callback: function (Error, string)): undefined

Utility method to get a temporary directory useful in browsers to be able to generate temp repos manually

Here for completeness

Parameters

  1. type: String:  
    the type of the node
  2. callback: function (Error, string):  

Returns

FactoryDaemon.prototype.spawn

spawn(options: Object, callback: Function): undefined

Spawn an IPFS node, either js-ipfs or go-ipfs

Options are:

  • init bool - should the node be initialized
  • initOptions Object, it is expected to be of the form {bits: <size>}, which sets the desired key size
  • start bool - should the node be started
  • repoPath string - the repository path to use for this node, ignored if node is disposable
  • disposable bool - a new repo is created and initialized for each invocation
  • config - ipfs configuration options
  • args - array of cmd line arguments to be passed to ipfs daemon
  • exec string (optional) - path to the desired IPFS executable to spawn, this will override the exec set when creating the daemon controller factory instance

Parameters

  1. options: Object (={}):  
    various config options and ipfs config parameters
  2. callback: Function:  
    (err, [ ipfs-api instance , Node (ctrl) instance ] ) - a callback that receives an array with an ipfs-instance attached to the node and a Node

Returns

tmpDir

Utility method to get a temporary directory useful in browsers to be able to generate temp repos manually

Parameters

  1. type: String:  
    the type of the node
  2. callback: function (Error, string):  

Returns

FactoryInProc

Spawn JSIPFS instances (aka in process nodes)

static

FactoryInProc.version

version(options: Object, callback: function (Error, string)): undefined

Get the version of the currently used go-ipfs binary.

Parameters

  1. options: Object (={}):  
  2. callback: function (Error, string):  

Returns

instance

FactoryInProc.prototype.tmpDir

tmpDir(type: string, callback: function (Error, string)): undefined

Utility method to get a temporary directory useful in browsers to be able to generate temp repos manually

Here for completeness

Parameters

  1. type: string:  
    the type of the node
  2. callback: function (Error, string):  

Returns

FactoryInProc.prototype.spawn

spawn(opts: Object, callback: Function): undefined

Spawn JSIPFS instances

Options are:

  • init {bool|Object} - should the node be initialized
  • initOptions Object, it is expected to be of the form {bits: <size>}, which sets the desired key size
  • start bool - should the node be started
  • repoPath string - the repository path to use for this node, ignored if node is disposable
  • disposable bool - a new repo is created and initialized for each invocation
  • config - ipfs configuration options
  • args - array of cmd line arguments to be passed to ipfs daemon
  • exec string (optional) - path to the desired IPFS executable to spawn, this will override the exec set when creating the daemon controller factory instance

Parameters

  1. opts: Object (={}):  
    various config options and ipfs config parameters
  2. callback: Function:  
    (err, [ ipfs-api instance , Node (ctrl) instance ] ) - a callback that receives an array with an ipfs-instance attached to the node and a Node

Returns

apiAddr

Get the address of connected IPFS API.

Returns

Multiaddr

apiAddr

Set the address of connected IPFS API.

Parameters

  1. addr: Multiaddr:  

Returns

void

gatewayAddr

Get the address of connected IPFS HTTP Gateway.

Returns

Multiaddr

gatewayAddr

Set the address of connected IPFS Gateway.

Parameters

  1. addr: Multiaddr:  

Returns

void

init

Initialize a repo.

Parameters

  1. initOpts: Object (={}):  
  2. initOpts.keysize: number (=2048):  
    The bit size of the identiy key.
  3. initOpts.directory: string (=IPFS_PATH):  
    The location of the repo.
  4. cb: function (Error, Node):  

Returns

cleanup

Delete the repo that was being used. If the node was marked as disposable this will be called automatically when the process is exited.

Parameters

  1. cb: function (Error):  

Returns

start

Start the daemon.

Parameters

  1. flags: Array<string> (=[]):  
    Flags to be passed to the ipfs daemon command.
  2. cb: function (Error, IpfsApi):  

Returns

stop

Stop the daemon.

Parameters

  1. cb: function (Error)?:  

Returns

killProcess

Kill the ipfs daemon process.

First SIGTERM is sent, after 7.5 seconds SIGKILL is sent if the process hasn't exited yet.

Parameters

  1. cb: function ()?:  
    Called when the process was killed.

Returns

pid

Get the pid of the ipfs daemon process.

Parameters

  1. cb: Function:  

Returns

getConfig

Call ipfs config

If no key is passed, the whole config is returned as an object.

Parameters

  1. key: string?:  
    A specific config to retrieve.
  2. cb: function (Error, (Object | string)):  

Returns

setConfig

Set a config value.

Parameters

  1. key: string:  
  2. value: string:  
  3. cb: function (Error):  

Returns

Node

ipfsd for a js-ipfs instance (aka in-process IPFS node)

Extends EventEmitter.

Parameters

  1. opts: Object?:  

instance

Node.prototype.apiAddr

apiAddr

Get the address of connected IPFS API.

Returns

Multiaddr

Node.prototype.gatewayAddr

gatewayAddr

Get the address of connected IPFS HTTP Gateway.

Returns

Multiaddr

Node.prototype.repoPath

repoPath

Get the current repo path

Returns

Node.prototype.started

started

Is the node started

Returns

Node.prototype.env

env

Is the environment

Returns

Node.prototype.init

init(initOptions: Object, callback: function (Error, Node)): undefined

Initialize a repo.

Parameters

  1. initOptions: Object (={}):  
  2. initOptions.bits: number (=2048):  
    The bit size of the identiy key.
  3. initOptions.directory: string (=IPFS_PATH):  
    The location of the repo.
  4. initOptions.pass: string?:  
    The passphrase of the keychain.
  5. callback: function (Error, Node):  

Returns

Node.prototype.cleanup

cleanup(callback: function (Error)): undefined

Delete the repo that was being used. If the node was marked as disposable this will be called automatically when the process is exited.

Parameters

  1. callback: function (Error):  

Returns

Node.prototype.start

start(flags: Array<string>, callback: function (Error, IpfsApi)): undefined

Start the daemon.

Parameters

  1. flags: Array<string> (=[]):  
    Flags to be passed to the ipfs daemon command.
  2. callback: function (Error, IpfsApi):  

Returns

Node.prototype.stop

stop(callback: function (Error)?): undefined

Stop the daemon.

Parameters

  1. callback: function (Error)?:  

Returns

Node.prototype.killProcess

killProcess(callback: function ()): undefined

Kill the ipfs daemon process.

First SIGTERM is sent, after 10.5 seconds SIGKILL is sent if the process hasn't exited yet.

Parameters

  1. callback: function ():  
    Called when the process was killed.

Returns

Node.prototype.pid

pid(): number

Get the pid of the ipfs daemon process.

Returns

Node.prototype.getConfig

getConfig(key: string?, callback: function (Error, (Object | string))): undefined

Call ipfs config

If no key is passed, the whole config is returned as an object.

Parameters

  1. key: string?:  
    A specific config to retrieve.
  2. callback: function (Error, (Object | string)):  

Returns

Node.prototype.setConfig

setConfig(key: string, value: string, callback: function (Error)): undefined

Set a config value.

Parameters

  1. key: string:  
  2. value: string:  
  3. callback: function (Error):  

Returns

Node.prototype.replaceConfig

replaceConfig(config: object, callback: function (Error)): undefined

Replace the current config with the provided one

Parameters

  1. config: object:  
  2. callback: function (Error):  

Returns

Node.prototype.version

version(callback: function (Error, string)): undefined

Get the version of ipfs

Parameters

  1. callback: function (Error, string):  

Returns