/delib

A lightweight and non-restrictive library and CLI for Ethereum and IPFS that provides the core methods needed to build decentralized applications.

Primary LanguageJavaScript

DeLib

You must install geth (OSX commands below, see link for more information or other platforms):

brew tap ethereum/ethereum
brew install ethereum

Classes

Ethereum
IPFS

Constants

path

Model for setting deployed contract addresses in a plain text file and getting those addresses.

Functions

findConfig(originalDirectory, levels)Object

Recursively calls up directories from this file to find delib.js configuration file. If it doesn't find one it gets the default config file.

Ethereum

Kind: global class

new Ethereum()

Create an Ethereum object. Will need to use Ethereum.init() to connect to the Web3 RPC provider and use the Ethereun object methods

ethereum._getBuiltContract(contractName) ⇒ Contract

Kind: instance method of Ethereum
Returns: Contract - The built contract

Param Type Description
contractName string Name of contract in the directory path provided in Ethereum.contract.build

ethereum.buildContracts(contractFiles, contractPath, buildPath)

Builds Solidity contracts.

Kind: instance method of Ethereum

Param Type Description
contractFiles array Array of contract file names in the directory path provided in Ethereum.config.contracts
contractPath string Optional. Directory path where contract files are located. If none is given the directory path will be retrieved from config.path.
buildPath string Optional. Directory path where built contracts will be put. If none is given the directory path will be retrieved from config.built.

ethereum.init(rpcHost, rpcPort, contractOptions) ⇒ Web3

Initializes a RPC connection with a local Ethereum node. The RPC provider is set in Ethereum.config.rpc.port. Need to call before using the Ethereum object. If RPC connection is already initalized and valid the RPC connection will be set to the current provider.

Kind: instance method of Ethereum
Returns: Web3 - The Web3 object Ethereum uses set up to the RPC provider

Param Type Description
rpcHost string The host URL path to the RPC connection. Optional. If not given the rpcHost path will be taken from Ethereum.config.rpc.host.
rpcPort number The port number to the RPC connection. Optional. If not given the rpcPort path will be taken from Ethereum.config.rpc.port.
contractOptions Object Options to set up the contract paths. Takes in path, built, and address properties.

ethereum.initIPC(ipcPath) ⇒ Web3

Initializes an IPC connection with a local Ethereum node. The IPC provider is set in Ethereum.config.ipc.host. Need to call before using the Ethereum object IPC methods.

Kind: instance method of Ethereum
Returns: Web3 - The Web3 object Ethereum uses for its IPC connection.

Param Type Description
ipcPath string Path to the IPC provider. Example for Unix: process.env.HOME + '/Library/Ethereum/geth.ipc'

ethereum.check() ⇒ bool

Checks the connection to the RPC provider

Kind: instance method of Ethereum
Returns: bool - The true or false status of the RPC connection

ethereum.changeAccount(index) ⇒ string

Change the account address being used by the Ethereum object.

Kind: instance method of Ethereum
Returns: string - The account address now being used.

Param Type Description
index number Index of the account address returned from web3.eth.accounts to change to.

ethereum.createAccount(password) ⇒ Promise

Creates a new Ethereum account. The account will be located in your geth Ethereum directory in a JSON file encrpyted with the password provided. process.exit() needs to be called in Promise or the method will run indefinately. Don't use process.exit() if using method in Electron.

Kind: instance method of Ethereum
Returns: Promise - Promise return is a string with the newly created account's address.

Param Type Description
password string The password to create the new account with.

ethereum.unlockAccount(address, password, timeLength) ⇒ boolean

Unlocks an Ethereum account. process.exit() needs to be called in Promise or the method will run indefinately. Don't use process.exit() if using method in Electron.

Kind: instance method of Ethereum
Returns: boolean - Status if account was sucessfully unlocked.

Param Type Description
address string The address of the account.
password string Password of account.
timeLength number Time in seconds to have account remain unlocked for.

ethereum.getBalanceEther(index) ⇒ number

Get the Ether balance of an account in Ether denomination.

Kind: instance method of Ethereum
Returns: number - The amount of Ether contained in the account.

Param Type Description
index number Index of the account to check the balance of in Ether.

ethereum.getBalanceWei(index) ⇒ number

Get the Ether balance of an account in Wei denomination. 1 Ether = 1,000,000,000,000,000,000 wei

Kind: instance method of Ethereum
Returns: number - The amount of Ether in Wei contained in the account.

Param Type Description
index number Index of the account to check the balance of inWei.

ethereum.toWei(amount) ⇒ number

Convert an Ether amount to Wei

Kind: instance method of Ethereum
Returns: number - Converted Wei amount.

Param Type Description
amount number Amount to convert. Can also be a BigNumber object.

ethereum.toEther(amount) ⇒ number

Convert a Wei amount to Ether.

Kind: instance method of Ethereum
Returns: number - Converted Ether amount.

Param Type Description
amount number Amount to convert. Can also be a BigNumber object.

ethereum.deploy(contractName, args, options) ⇒ Promise

Deploy a built contract.

Kind: instance method of Ethereum
Returns: Promise - The response is a Contract object of the deployed instance.

Param Type Description
contractName string Name of built contract located in the directory provided in Ethereum.config.built.
args Array Arguments to be passed into the deployed contract as initial parameters.
options Object Transaction options. Options are: {from: contract address, value: number, gas: number, gasValue: number}.

ethereum.exec(contractName) ⇒ Contract

Calls a deployed contract. Will take the address provided in the config address

Kind: instance method of Ethereum
Returns: Contract - Contract object that you can call methods with.

Param Type Description
contractName string Name of built contract located in the directory provided in Ethereum.config.built.

ethereum.execAt(contractName, contractAddress) ⇒ Contract

Calls a deployed contract at a specific address.

Kind: instance method of Ethereum
Returns: Contract - Contract object that you can call methods with.

Param Type Description
contractName string Name of built contract located in the directory provided in Ethereum.config.built.
contractAddress string Address of the contract.

ethereum.getEventLogs(contractName, contractAddress, method, filter) ⇒ Promise

Kind: instance method of Ethereum
Returns: Promise - The response contains an array event logs.

Param Type Description
contractName string Name of built contract located in the directory provided in Ethereum.config.built.
contractAddress string Address of the contract.
method string The name of the event method.
filter Object Options to filter the events. Default: { address: contractAddress }.

IPFS

Kind: global class

new IPFS()

Create a new IPFS object

ipfS.init(manualConfig) ⇒ IPFS

Initalize the connection to an IPFS node. If no network configuration is given the configuration will be taken from IPFS.config.

Kind: instance method of IPFS
Returns: IPFS - IPFS object

Param Type Description
manualConfig Object Object containing the configuration parameters for IPFS. Default: { host: 'localhost', port: 5001, protocol: 'http' }

ipfS.daemon()

Open an IPFS daemon is a child process

Kind: instance method of IPFS

ipfS.addFiles(filePaths) ⇒ Promise

Add a single file or multiple files to the connected IPFS node.

Kind: instance method of IPFS
Returns: Promise - Response of Promise is an array of objects with {path: string, hash: string, size: number, file: filePath}

Param Type Description
filePaths string Path to file. Can also be an array of paths.

ipfS.download(hashAddress, writePath) ⇒ Promise

Retrieve a file based on his hash address from the IPFS network.

Kind: instance method of IPFS
Returns: Promise - Response of Promise is an array of all file buffer chunks.

Param Type Description
hashAddress string Hashaddress of the file.
writePath string Path in which to write the file to.

ipfS.links(hashAddress) ⇒ Promise

Take a hash address corresponding to a particular file and retrieve the Merkle Dag links of that file.

Kind: instance method of IPFS
Returns: Promise - Response of Promise is an array of Objects with DAGLink info. {name: String, hashAddress: String, size: Number, hash: Buffer of hash address}

Param Type Description
hashAddress string Hash address of the file.

ipfS.pin(hashAddress) ⇒ Promise

Pin a hash address to the connected to IPFS node.

Kind: instance method of IPFS
Returns: Promise - Response of Promise is an array of the hash addresses of the pinned files.

Param Type Description
hashAddress string Hash address of the file.

ipfS.unpin(hashAddress) ⇒ Promise

Unpin a hash address to the connected to IPFS node.

Kind: instance method of IPFS
Returns: Promise - Response of Promise is an array of the hash addresses of the unpinned files.

Param Type Description
hashAddress string Hash address of the file.

path

Model for setting deployed contract addresses in a plain text file and getting those addresses.

Kind: global constant

findConfig(originalDirectory, levels) ⇒ Object

Recursively calls up directories from this file to find delib.js configuration file. If it doesn't find one it gets the default config file.

Kind: global function
Returns: Object - The configuration object.

Param Type Description
originalDirectory string The original directory. Pass in process.cwd()
levels number The number of folders to go up