Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

delib

4.1.19 • Public • Published

Delib

Delib Logo

Simple Ethereum framework for DApps and contract management

Delib is designed to be easy to learn and allow freedom when developing with Ethereum. Its features include:

  • A promise based library that provides the core abstractions needed for building DApps on Ethereum.
  • A command tool for smart contract interaction. It lets you compile, build, deploy, execute methods, and get their event logs.
  • Option to automatically estimate your transaction gas costs for contract deployment and methods.
  • The saving of deployed contract addresses to use or reference later.
  • The ability to create and unlock Ethereum accounts using IPC.

Table of Contents

Requirements

You need to have an Ethereum node to connect with. Delib uses geth. The Mac OSX install commands with brew are shown below. Click here for additional install information.

brew tap ethereum/ethereum
brew install ethereum

Delib uses npm web3 version 0.20.

Installation and Setup

Global install

Install globally to use the command tool.

npm install -g delib

Local install

Install locally to require the library.

npm install delib --save

Then require the library in your scripts.

const delib = require('delib');

Project creation

To create a project call the following in the command line.

delib init

The project is structured like this:

project/
├── addresses/        - (addresses of deployed contracts)
├── built/            - (built Solidity contracts)
├── contracts/        - (Solidity contracts .sol)
├── delib.js/         - (delib config file)

You can have the init command create a custom project structure for you. If you pass in the option --config it will only create the config file. Open the file to set your own project file paths and then call delib init again.

You don't need to create a project to use Delib. More information is given in the usage section.

Configuration

A file called delib.js gets made when you create a project. It contains your project's configuration options. Use this to adjust your project file paths, connection options, and default command transaction options.

{
  /** Project file paths */
  paths: {
    contract: './contracts', // Relative path to Solidity contracts
    built: './built', // Relative path to built contracts
    address: './addresses' // Relative path to deployed contract addresses
  },

  /** RPC connection options */
  rpc: {
    host: 'localhost',
    port: 8545
  },

  /** IPC connection options */
  ipc: {
    host: null // Relative path to IPC host
  }

};

Usage

Usage outside project

Delib can be used outside a project. Outside a project file paths will be relative to your process point of entry. Connection options will also need to be specified. You can specify these with the library and pass them in as options if using the command tool.

Contract addresses

Your contract's deployed addresses are saved in a plain text file with a file name of ContractnameAddresses. Each address is separated by a new line, and the most recent address is at the bottom of the list. The library and command tool use that address when no address is specified and you can manually add your own addresses to this file.

Development node

A good choice would be devchain for your Ethereum development node. It gives you a development geth server and helps you create private Ethereum blockchains. You can adjust the blockchain's mining difficulty and it automates mining and account Ether distribution. To install:

npm install -g devchain

Another option is testrpc.

npm install -g ethereumjs-testrpc

Library and command integration

Building a contract with the command tool will allow it to be accessible with the library. Also, deploying a contract using the library will make the following command tool calls refer to the library's deployed address, and vice versa. You can deploy contracts and then quickly test whether your methods are working with commands.

Command Tool

The command tool lets you interact with smart contracts both on and off the blockchain. It lets you compile and build Solidity contracts into a JavaScript file that you can then require. Then you can deploy the contract onto a blockchain and also execute methods and get event logs. It also allows you to create, unlock, and get the balance of your accounts.

Set connection options and project paths

The default connection and file path options are taken from the delib.js config file. Outside a project all project paths will be relative to where you're calling the command, and the RPC connection will default to localhost at port 8545. You can also specify connection options and paths as options. Non IPC commands will connect via RPC unless you specify an IPC option.

Options Type Description
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host
-o --contract <path> Path to contracts folder
-b --built <path> Relative path to built contracts folder
-a --address <path> Relative path to contract addresses folder

Adjust transaction options

The default transaction options for the commands are located in delib.js. You can also pass in your own transaction options.

Options Type Description
-i --account <index> Account index to use for transaction
-f --from <address> From transaction option. Replaces --account
-t --to <address> To transaction option'
-v --value <ether> Value transaction option in wei
-g --gas <number> Gas transaction option. Estimated if not given or set to 0
-p --gasprice <number> Gas price transaction option
-n --nonce <number> Nonce transaction option
-m --maxgas <number> Max gas allowed when estimating

Build contract

delib build [files...]>

Build a Solidity contract with the file name Contract.sol.

delib build Contract

Deploy contract

delib deploy <contractName> [args...]

Deploy a contract and pass in two arguments for its constructor. If no gas amount is given it will be estimated for you.

delib deploy Contract hello 30

Display built contracts

delib contracts

Displays all built contracts

delib contracts

Display contract info

delib info <contractName>

Show all the contract methods along with their inputs and outputs, contract events, and the current address being used. Use this to not have to constantly reference your .sol contract file.

delib info Contract

Execute contract method

delib exec <contractName> <methodName> [args...]

Execute the method setNumbers on a deployed contract and pass in two numbers. The transaction options of 10000 gas with a gas value of 50000 are set as options. If no gas amount is given it will be estimated for you.

delib exec Contract setNumbers 10 20 --gas 10000 --gasprice 50000

If you only wish to call the method, which uses no gas because it doesn't change blockchain state, pass in the option --call. Labeling your Solidity method with constant makes it call automatically.

delib exec Contract getNumbers --call

Get the logs of an event

delib events <contractName> <eventName> [blocksBack]

Get all the logs of an event called numbersEvent.

delib events Contract numbersEvent all

Get the logs from the last 10 blocks.

delib events Contract numbersEvent 10

Watch for events

delib watch <contractName> <eventName>

Watch for events from lettersEvent.

delib watch Contract lettersEvent

Set the address of a contract

delib set <contractName> <contractAddress>

Set the address of a contract to use. This will set its address for both the command tool and library until another contract is deployed.

delib set Contract 0xa9b15bfe1d4e7bed407a011e54af36462fa0e067

Get account balance

delib balance <accountIndex> [denomination]

Get the Ether balance of your first account.

delib balance 0

Get the wei balance of your second account.

delib balance 1 wei

Create an account

delib create <password>

Create an account with the password "hunter1".

delib create hunter1

Unlock an account

delib unlock <accountIndex> <password> [unlockTime]

Unlock your first account for 10000 seconds.

delib unlock 0 hunter1 10000

Command Tool API Link

Library

The library gives you the freedom to customize your DApp development to fit your specific needs. You can easily write your own contract migration scripts, interact with contracts from within your app, and write contract tests.

File paths

delib.contracts.paths

To specify your own file paths use the delib.contracts.paths object. Inside a project the paths will be relative to your project root (where delib.js is located). Outside a project they will be relative to your process point of entry.

delib.contracts.paths.contract = 'relative path to contract folder';

delib.contracts.paths.built = 'relative path to built folder';

delib.contracts.paths.address = relative path to addresses folder';

Connections

Your project's delib.js file sets up your RPC and IPC connections. You can also pass in connection options as arguments.

RPC provider

delib.init(rpcHost, rpcPort)

To connect with the options in delib.js:

delib.init();

Specify your own connection arguments by passing in a RPC host and a RPC port number.

delib.init('localhost', 8000);

IPC provider

delib.initIPC(ipcPath)

To connect with the options in delib.js:

delib.initIPC();

You can pass in an IPC path as an argument.

delib.initIPC('<path>/<to>/geth.ipc'); // To use the IPC provider to perform transaction you will need to changeProviders

The IPC connection remains on until you close it. To close it use:

delib.closeIPC();

Switching providers

delib.changeProvider(type)

The provider is set to the first one initialized. To switch between the two:

delib.changeProvider('rpc');

delib.changeProvider('ipc');

These return a boolean indicating whether or not the change went thru.

You can also check their connection status.

delib.checkConnection(type)

delib.checkConnection('rpc');

delib.checkConnection('ipc');

Adjust options

delib.account
delib.options

To chooose a default account index for transactions use delib.account. The index corresponds to the web3.eth.accounts array. By default it is 0.

delib.account = 0;

delib.options contains the default options for your transactions. It contains the Ethereum transaction options as well as delib options. These options can be passed into deploy or contract method calls, and they'll overwrite the defaults.

You can pass in an account option in your deploy or contract method call and it'll use that account index for your transaction.

If a gas option of 0 is specified gas will be estimated for you, and maxGas is the max gas allowed in gas estimates.

delib.options = {
  /** Default transaction options */
  from: undefined,
  to: undefined,
  value: undefined,
  gas: 0,
  gasPrice: undefined,
  data: undefined,
  nonce: undefined,

  /** Default delib options*/
  account: undefined,
  maxGas: undefined  
};

Build contracts

delib.build(contractFiles, contractPath, buildPath)

Pass in a file name or an array of file names you wish you build from your project's contracts/ folder to your project's built/ folder.

delib.build('Test')
  .then(contracts => {
    console.log(contracts); // An array of all the contracts built.
  });

Deploy contracts

delib.deploy(contractName, args, options)

The addresses of your deployed contracts are saved in your project's addresses/ folder. Passing in an array for the constructor arguments is optional, however to pass in an options object you will need to pass in an empty arguments array. The promise returns an instance of the contract which you can use to make method calls.

To deploy a contract, estimate gas amount, and call a method on the instance:

options = {
  gas: 0 // Set gas at 0 to have it estimated for you
}

delib.deploy('Test', [arg1, arg2, arg3], options)
  .then(instance => {
    const address = instance.address;

    return instance.testMethod();
  })
  .then(tx => {

  })
  .catch(err => {

  });

You can estimate the gas usage for deploying a contract.

delib.deploy.estimate(contractName, args, options)

delib.deploy.estimate('Test', [arg1, arg2, arg3])
  .then(gasEstimate => {

  })
  .catch(err => {

  });

You can get an array of all previously deployed addresses with delib.contracts.addresses.getAll('contractName'). The most recently deployed address is the array's last index. Use this to access previously deploy contracts.

Execute contract methods

delib.exec(contractName)
delib.execAt(contractName, contractAddress)

It will perform a transaction (which requires gas) or if it will just call and return a value by whether or not you labeled your function with constant in your Solidity contract.

To call a contract at the address you last deployed it:

options = {
  gas: 0 // Gas set at 0 will be estimated
};

delib.exec('Test').testMethod(arg1, arg2, options)
  .then(tx => {

  })
  .catch(err => {

  });

You can estimate the gas usage for calling a contract method.

delib.exec(contractName).estimate
delib.execAt(contractName, contractAddress).estimate

delib.exec('Test').estimate.testMethod(arg1, arg2)
  .then(gasEstimate => {

  })
  .catch(err => {

  })

Get event logs

delib.events(contractName, eventName, blocksBack, filter)
delib.eventsAt(contractName, contractAddress, eventName, blocksBack, filter)

The code below gets the logs from an event called testEvent on the contract Test. It searches the last 100 blocks. To have it search all blocks pass in 'all' instead of a number.

delib.events('Test', 'testEvent', 100)
  .then(logs => {

  })
  .catch(err => {

  });

Watch events

delib.watch(contractName, eventName, filter, callback)
delib.watchAt(contractName, contractAddress, eventName, filter, callback)

You can watch a contract for when it gets a new event.

delib.watch('Test', 'testEvent', function(err, log) {
  if (!err) {
    // Do something with the log  
  }
});

To stop the watch listener set the watch method to a variable and call .stop() on it.

const watch = delib.watch('Test', 'testEvent', function(err, log) {
  if (!err) {
    // Do something with the log  
  }
});

watch.stop(); // Stops the event listener

Event filter object

You can pass in a filter object to filter the results of your events and watch methods. You can set the properties of the filter as plain values, an array of values, or a callback. By default the address property is the contract address.

If it's just a value it will need to match the log's property or it will be filtered. If its an array then one of the values will need to match. For callbacks, it takes the value of the log as its parameter, and it gets filtered if it returns anything other than true.

Click here to see all the properties of the event log object.

The following shows a filter that filters all logs except even numbered blocks, logs with an event argument name of James, and logs with age arguments of 18, 25, and 26.

filter = {
  blockNumber: function(number) {
    if (number % 2 === 0) {
      return true;
    } else {
      return false;
    }
  },
  // args contains the actual event arguments
  args: {
    name: 'James',
    age: [18 ,25, 26]
  }
};

delib.events('Test', 'testEvent', 'all', filter)
  .then(logs => {

  })
  .catch(err => {

  });

delib.watch('Test', 'testEvent', filter, function(err log) {
  if (!err) {
    // Do something with filtered log
  }
});

Account balances

delib.getBalance(index, type)

The method to get the balance of an account takes in the account index and the Ether denomination you would like the result to be in. If using this with an IPC connection it will return a Promise.

Get the balance of your first account in Ether, switch to IPC, then get it in wei:

delib.getBalance(0, 'Ether');

delib.changeProvider('ipc');

delib.getBalance(0, 'wei')
  .then(balance => {

  })

Create accounts

delib.createAccount(password)

This only works with an IPC connection. It creates an encrpyted JSON file containing your public and private key in your Ethereum blockchain's data directory.

delib.createAccount('hunter1')
  .then(address => {

  })

Unlock accounts

delib.unlockAccount(index, password, timeLength)

This only works with an IPC connection. Time length is in seconds.

delib.unlockAccount(1, 'hunter2', 10000)
  .then(status => {

  })

Library API Link

Example

Initialize the project structure.

delib init

Install the delib package

npm install delib --save

Create a contract file called Messages.sol in the contracts/ folder. This contract sets and stores a simple message that can be watched for or retrieved.

pragma solidity 0.4.23;

contract Messages {

  event messageEvent(
    string _message
  );

  address owner;
  string message;

  constructor(string _message) public {
    owner = msg.sender;
    message = _message;
  }

  function getOwner() public constant returns (address) {
    return owner;
  }

  function setMessage(string _message) public {
    message = _message;
    emit messageEvent(_message);
  }

  function getMessage() public constant returns (string) {
    return message;
  }
}

Build Messages.sol with the command tool.

delib build Messages

A file called Messages.json will be created in the built/ folder.

Deploy Messages using a command with arguments for the constructor. Gas will be estimated for you.

delib deploy Messages 'hello'

A file called MessagesAddresss will be created in your addresses/ folder with the deployed contract's address.

Watch for a message being set:

delib watch Messages messageEvent

Create a file called script.js

const delib = require('delib');

delib.init();

// Adjust the default transaction options
delib.options = {
  value: 0,
  gas: 100000,
};

// Call a method on the contract Messages
delib.exec('Messages').getMessage()
  .then(message => {
    console.log(message); // -> hello

    // Call another method with your 2nd account and pass in options
    delib.account = 1;
    return delib.exec('Messages').setMessage('coffee', {
      gas: 100000 // gas will no longer be estimated
    });
  })
  .then(tx => {
    console.log(tx); // displays the transaction receipt
    return delib.exec('Messages').getMessage();
  })
  .then(message => {
    console.log(message); // -> coffee  
  })
  .catch(err => {
    console.log(err);
  });

This script sets a message on the contract and calls it again to get the message saved.

Upon running the script, your command for watching for messages set should show:

Watching for events:
{ _message: 'coffee' }

You can then call methods on Messages in the command line.

delib exec Messages getMessage
Response: coffee

Then you can set another message with the command line. Gas will be estimated for the following transaction.

delib exec Messages setMessage apples
Response: 0x456e1934eef8c38b9de6c8fd09df0a285c8c42f86373d2c2a74157a68592209b
delib exec Messages getMessage
Response: apples

Support

If you found Delib useful please leave a star on GitHub or give feedback!

API Reference

Command Tool

delib init -c --config

Create the config file delib.js and the project structure.

Params Type Description
-c --config -- If used the command will only create the delib.js config file

delib build [files...] -h --rpchost <value>, -r --rpcport <port>, -c --ipchost [path], -o --contract <path>, -b --built <path>

Compile and build a Solidity smart contract .sol into a JavaScript file .sol.js that you can require. File paths are set in the delib.js config file or passed in as command line options. By default these are your project's contracts/ and built/ folders.

Params Type Description
[files...] string Names of Solidity contract
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host
-o --contract <path> Path to contracts folder
-b --built <path> Path to build contracts folder

delib deploy <contractName> [args...], -i --account <index>, -f --from <address>, -t --to <address>, -v --value <ether>, -g --gas <number>, -p --gasprice <number>, -n --nonce <number>, -m --maxgas <number>, -h --rpchost <value>, -r --rpcport <port>, -c --ipchost [path], -b --built <path>, -a --address <path>

Deploy a built Solidity smart contract and save its address for later use with the CLI or library. File paths are set in the delib.js config file or passed in as command line options. By default these are your project's built/ and addresses/ folders.

Params Type Description
<contractName> string Name of built contract
[...args] strings Arguments to pass into method
-i --account <index> Account to use for transaction. Takes the account index
-f --from <address> From transaction option. Replaces --account
-t --to <address> To transaction option'
-v --value <ether> Value transaction option in wei
-g --gas <number> Gas transaction option. Estimated if not given or set to 0
-p --gasprice <number> Gas price transaction option
-n --nonce <number> Nonce transaction option
-m --maxgas <number> Max gas allowed when estimating
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host
-b --built <path> Relative path to built contracts folder
-a --address <path> Relative path to contract addresses folder

delib exec <contractName> <methodName> [args...], -i --account <index>, -f --from <address>, -t --to <address>, -v --value <ether>, -g --gas <number>, -p --gasprice <number>, -n --nonce <number>, -m --maxgas <number>, -h --rpchost <value>, -r --rpcport <port>, -c --ipchost [path], -b --built <path>, -a --address <path> --call

Perform a transaction or call a deployed contract's method. You can pass in a list of arguments. The most recent deployed contract address or set command address will be used.

Params Type Description
<contractName> string Name of built contract
<methodName> string Contract method name
[...args] strings Arguments to pass into method
-i --account <index> Account to use for transaction. Takes the account index
-f --from <address> From transaction option. Replaces --account
-t --to <address> To transaction option'
-v --value <ether> Value transaction option in wei
-g --gas <number> Gas transaction option. Estimated if not given or set to 0
-p --gasprice <number> Gas price transaction option
-n --nonce <number> Nonce transaction option
-m --maxgas <number> Max gas allowed when estimating
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host
-b --built <path> Relative path to built contracts folder
-a --address <path> Relative path to contract addresses folder
--call -- Forces method execution with a call

delib events <contractName> <eventName> [blocksBack], -h --rpchost <value>, -r --rpcport <port>, -c --ipchost [path], -b --built <path>, -a --address <path>

Get the logs of a deployed contract's event. By default it gets all logs starting from block 0. You can pass in how many blocks back you wish to get logs from.

Params Type Description
<contractName> number Name of built contract
<eventName> string Contract event name
[blocksBack] number Number of blocks back to get logs from
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host

delib watch <contractName> <eventName>, -h --rpchost <value>, -r --rpcport <port>, -c --ipchost [path], -b --built <path>, -a --address <path>

Watch for events

Params Type Description
<contractName> number Name of built contract
<eventName> string Contract event name
[blocksBack] number Number of blocks back to get logs from
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host

delib contracts -b --built <path>

Retrieves a list of all built contracts.

Params Type Description
-b --built <path> Relative path to built contracts folder

delib info <contractName>, -b --built <path>, -a --address <path>

Show contract info such as methods, events, and currently used address. It displays the method inputs, outputs, constant modifier, and payable modifier. It also displays the event args.

Params Type Description
<contractName> string Name of built contract
<contractAddress> string The address to bind to the contract
-b --built <path> Relative path to built contracts folder
-a --address <path> Relative path to contract addresses

delib set <contractName> <contractAddress>, -a --address <path>

Set the address of a contract to use.

Params Type Description
<contractName> string Name of built contract
<contractAddress> string The address to bind to the contract
-a --address <path> Relative path to contract addresses

delib balance <accountIndex> [denomination], -h --rpchost <value>, -r --rpcport <port>, -c --ipchost [path]

Get the balance of one of your account by its account index.

Params Type Description
<accountIndex> number Index of account
[denomination] string Denomination to get balance in. Defaults to 'ether'
-r --rpchost <value> RPC host
-h --rpcport <port> RPC port
-c --ipchost [path] Relative path to IPC host

delib create <password>, -c --ipchost [path]

Create a new Ethereum account.

Params Type Description
<password> string Account password
-c --ipchost [path] Relative path to IPC host

delib unlock <accountIndex> <password> [time], -c --ipchost [path]

Unlock an Ethereum account by its account index. The argument time defaults to a day.

Params Type Description
<accountIndex> number Index of account
<password> string Account password
[time] number Time to leave account unlocked in seconds
-c --ipchost [path] Relative path to IPC host

Library

delib.web3

The Web3 object being used as the current provider. Will first need to initialize a connection with delib.init() or delib.initIPC();

delib.web3RPC

The Web3 object used for RPC connections. Will first need to initialize a RPC connection with delib.init().

delib.web3IPC

The Web3 object used for IPC connections. Will first need to initialize an IPC connection with delib.initIPC(). This object will allow you to perform Web3 personal and admin tasks.

delib.gasAdjust

The amount to adjust gas when doing automatic gas estimates. Default is 0. It's calculated by this formula:

gasEstimate = gasEstimate + gasEstimate * gasAdjust

delib.account

The default index of the account used for transactions. The index uses the web3.eth.accounts array to get the account address. This can be overwritten by setting an address in delib.options.from, setting a from property in transaction options, or setting an account property (also an account index) in transaction options.

delib.options

The default options for delib methods. This object contains the default transaction options as well as the default delib options. If gas is 0 or null then it will be estimated automatically for each transaction. maxGas is the max gas allowed when estimating gas. Leave from null to get the address from delib.account or account. You can pass any of these properties inside the options object for deploy or exec transactions.

{
  /** Default transaction options */
  from: undefined,
  to: undefined,
  value: undefined,
  gas: 0,
  gasPrice: undefined,
  data: undefined,
  nonce: undefined,

  /** Default delib options*/
  account: undefined,
  maxGas: undefined
}

delib.contracts.paths

An object that contains the paths to the Solidity contracts, built contracts, and contract addresses. If using delib in a project these paths will be relative to your project root, otherwise they will be relative to your scripts. Assign paths to this object if you don't want to create a project or if you want to customize the paths.

delib.contracts.paths = {
  solidity: 'path to solidity contracts',
  built: 'path to built contracts',
  addresses: 'path to contract addresses'
}

delib.contracts.addresses.set(name, address)

Set an address for a contract to use for future transactions. It appends it to the addresses file of that particular contract, or creates it if it doesn't exist.

Returns: number - The index of the set address.

Param Type Description
name string Name of built contract
address string The address of the contract

delib.contracts.addresses.get(name, index)

Retrieves the addresses file of a contract and gets a deployed contract address based on index. If no index parameter is given it will return the latest address, which is at the bottom of the addresses file.

Returns: string - The contract address.

Param Type Description
name string Name of built contract
index number The index of the contract address

delib.contracts.addresses.getAll(name)

Retrieves the addresses file of a contract and return an array of all its deployed addresses.

Returns: Array - An array of deployed contract addresses.

Param Type Description
name string Name of built contract

delib.init(rpcHost, rpcPort) ⇒ Web3

Initializes a RPC connection with an Ethereum node. The RPC provider can be set in the delib.js config file or you can pass it in as arguments. This needs to be called before performing any methods that interact with an Ethereum node.

Returns: Web3 - The Web3 object being used as a provider (RPC or IPC).

Param Type Description
rpcHost string The host URL path to the RPC connection. Optional. If not given the rpcHost path will be taken from the config file.
rpcPort number The port number to the RPC connection. Optional. If not given the rpcPort path will be taken from config file.

delib.initIPC(ipcPath) ⇒ Web3

Initializes an IPC connection with an Ethereum node. The IPC provider can be set in the delib.js config file or you can pass it in as an argument. This needs to be called before using IPC functionality such as creating or unlocking an account. This returns a Web3 object connected via IPC that you call web3.personal and web3.admin methods on.

Returns: Web3 - The Web3 object delib 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'. Optional.

delib.closeIPC() => boolean

Closes the IPC connection

Returns boolean Status of the IPC connection

delib.checkConnection(type) => boolean

Check the status of a certain connection type (IPC or RPC)

Returns boolean Status of the connection.

Param Type Description
type string The connection type to test for ('rpc' or 'ipc')

delib.changeProvider(type) => boolean

Change the provider to use (RPC or IPC). It checks the connection status before switching. The connection will need to be initialized first before switching.

Returns boolean If the change went thru.

Param Type Description
type string The provider to change to ('rpc' or 'ipc')

delib.build(contractFiles, contractPath, buildPath)

Build a Solidity contract.

Returns: Array - Contracts built.

Param Type Description
contractFiles array Array of contract file names in the contracts folder
contractPath string Optional. Directory path where contract files are located. If none is given the directory path will be retrieved from delib.js or the contracts.paths object
buildPath string Optional. Directory path where built contracts will be put. If none is given the directory path will be retrieved from delib.js or the contracts.paths object.

delib.builtContract(contractName)

Require a built contract file with the project paths being used. It returns an ether-pudding contract object.

Returns: Contract - Ether-pudding contract object

Param Type Description
contractName string Name of contract

delib.deploy(contractName, args, options) ⇒ PromiseContractInstance

Deploy a built contract. If you have delib.options value set to 0 or pass in the option then your gas cost will be automatically estimated. The address is saved in your project's addresses/ folder and will be used for future contract calls and transactions.

Returns: Promise - The response is a Contract instance of the deployed instance. You can call methods on it.

Param Type Description
contractName string Name of built contract located in the directory provided in delib.js
args Array Arguments to be passed into the deployed contract as initial parameters.
options Object Transaction options.

delib.deploy.estimate(contractName, args, options) ⇒ Promisenumber

Estimate the gas usage for deploying a contract.

Returns: Promise - The response contains the estimated gas cost.

Param Type Description
contractName string Name of built contract located in the directory provided in delib.js
args Array Arguments to be passed into the deployed contract as initial parameters.
options Object Transaction options.

delib.exec(contractName) ⇒ ContractInstance

Calls or performs a transaction on a deployed contract. Will take the address provided in the config file. If you have delib.options value set to 0 or pass in the option into the contract method call your gas cost will be automatically estimated.

Returns: Contract - Contract instance that you can call methods with.

Param Type Description
contractName string Name of deployed contract

delib.exec(contractName).estimate ⇒ Promisenumber

Calls a deployed contract and methods called on the returned contract will return an estimated gas usage value.

Returns: number - Contract instance that you can estimate the gas usage of methods with.

Param Type Description
contractName string Name of deployed contract

delib.execAt(contractName, contractAddress) ⇒ ContractInstance

Calls a deployed contract at a specific address. If you have delib.options value set to 0 or pass it in as an option your gas cost will be automatically estimated.

Returns: Contract - Contract instance that you can call methods with.

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

delib.execAt(contractName, contractAddress).estimate ⇒ Promisenumber

Calls a deployed contract at a specified address and methods called on the contract will return the estimated gas usage.

Returns: Contract - Contract instance that you can estimate the gas usage of methods with.

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

delib.events(contractName, eventName, blocksBack, filter) ⇒ Promise

Gets the event logs of an event.

Returns: Promise => Array - Promise response contains an array event logs.

Param Type Description
contractName string Name of built contract.
eventName string The name of the event method.
blocksBack number The number of blocks back to get logs for. 'all' gets all blocks. Defaults to 'all'
filter Object Object to filter the event logs. The filter properties can be ordinary values, an array of values, or a callback function. If it's just a value then it must match with the log's value or it's filtered. If it's an array one of the values must match. The callbacks take the log value as a parameter and it must return true. The filter's address property by default is the contract address.

delib.eventsAt(contractName, contractAddress, eventName, blocksBack, filter) ⇒ Promise

Gets the event logs for an event.

Returns: Promise => Array - Promise response contains an array event logs.

Param Type Description
contractName string Name of built contract.
contractAddress string Address of the contract.
eventName string The name of the event method.
blocksBack number The number of blocks back to get logs for. 'all' gets all blocks. Defaults to 'all'
filter Object Object to filter the event logs. The filter properties can be ordinary values, an array of values, or a callback function. If it's just a value then it must match with the log's value or it's filtered. If it's an array one of the values must match. The callbacks take the log value as a parameter and it must return true. The filter's address property by default is the contract address.

delib.watch(contractName, eventName, filter, callback)

Set up a listener to watch for new events. To stop the listener set the watch method to a variable and call watch.stop().

Returns Object

Param Type Description
contractName string Name of built contract.
eventName string The name of the event method.
filter Object Object to filter the event logs. The filter properties can be ordinary values, an array of values, or a callback function. If it's just a value then it must match with the log's value or it's filtered. If it's an array one of the values must match. The callbacks take the log value as a parameter and it must return true. The filter's address property by default is the contract address. Optional: you may pass the callback in its place
callback Function Callback to watch the events with. Takes parameters err and log

delib.watchAt(contractName, contractAddress, eventName, filter, callback)

Set up a listener to watch for new events. To stop the listener set the watch method to a variable and call watch.stop().

Returns Object

Param Type Description
contractName string Name of built contract.
contractAddress string Address of the contract.
eventName string The name of the event method.
filter Object Object to filter the event logs. The filter properties can be ordinary values, an array of values, or a callback function. If it's just a value then it must match with the log's value or it's filtered. If it's an array one of the values must match. The callbacks take the log value as a parameter and it must return true. The filter's address property by default is the contract address. Optional: you may pass the callback in its place
callback Function Callback to watch the events with. Takes parameters err and log

delib.createAccount(password) ⇒ Promise

Creates a new Ethereum account. Needs an IPC connection.

Returns: Promise => string - Promise response is a string of the newly created account address.

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

delib.unlockAccount(index, password, timeLength) ⇒ boolean

Unlocks an Ethereum account. Needs an IPC connection.

Returns: Promise => boolean - Promise response is status of whether or not the account got unlocked.

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

delib.getBalance(index, type) ⇒ number

Get the Ether balance of an account in a specified denomination.

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.
type string The denomination. Default: 'ether'

Keywords

Install

npm i delib

DownloadsWeekly Downloads

7

Version

4.1.19

License

MIT

Unpacked Size

145 kB

Total Files

35

Last publish

Collaborators

  • avatar