Cipherem

Cipjs-unit

The cipjs-unit package is a utility library designed for the Cipherem blockchain. It provides functions for converting between different units of the Cipherem currency, similar to how ethjs-unit works for Ethereum. This library allows developers to easily handle conversions between the smallest unit (wei) and larger units such as 'cip', 'kwei', 'mwei', etc.

cipjs-unit

A clone of ethjs-unit package named as cipjs-unit for the Cipherem chain. A simple module for handling Ethereum unit conversion adapted for the Cipherem blockchain.

Installation

To install cipjs-unit, use the following command:

npm install --save cipjs-unit

Usage

Here is a basic usage example:

const unit = require('cipjs-unit');

var val1 = unit.toWei(249824778, 'cip');
// result: <BN ...> 249824778000000000000000000

var val2 = unit.fromWei('249824778000000000000000000', 'cip');
// result: '249824778'

About

cipjs-unit is a port from the cipweb3.js library, specifically for handling unit conversion between the various types of Cipherem currency units. The toWei method returns a BN instance, while fromWei always returns a string number.

Amorphic Data Formatting

cipjs-unit uses the number-to-bn module to format all number values (hex or otherwise) into digestible BN.js number instances.

Methods Available & Objects

  • unitMap: { unitName: singleUnitWeiValue, ... }
  • getValueOfUnit: <Function (unit) : (BN)>
  • toWei: <Function (value, unit) : (BN)>
  • fromWei: <Function (value, unit) : (String)>

Supported Units

'wei':          '1',
'kwei':         '1000',
'Kwei':         '1000',
'babbage':      '1000',
'femtoether':   '1000',
'mwei':         '1000000',
'Mwei':         '1000000',
'lovelace':     '1000000',
'picoether':    '1000000',
'gwei':         '1000000000',
'Gwei':         '1000000000',
'shannon':      '1000000000',
'nanoether':    '1000000000',
'nano':         '1000000000',
'szabo':        '1000000000000',
'microether':   '1000000000000',
'micro':        '1000000000000',
'finney':       '1000000000000000',
'milliether':   '1000000000000000',
'milli':        '1000000000000000',
'cip':          '1000000000000000000',
'kether':       '1000000000000000000000',
'grand':        '1000000000000000000000',
'mether':       '1000000000000000000000000',
'gether':       '1000000000000000000000000000',
'tether':       '1000000000000000000000000000000'

Why BN.js?

ethjs has adopted the policy of using BN.js across all modules for several reasons:

  • Lighter than alternatives (BigNumber.js)
  • Faster than most alternatives (see benchmarks)
  • Used by the Ethereum foundation across all ethereumjs repositories
  • Critical JS dependency for many Ethereum packages (e.g., elliptic)
  • No support for decimals or floats, ensuring greater precision (Ethereum blockchain does not support float values or decimal numbers)

Contributing

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

Guides

You'll find more detailed information on using cipjs-unit and tailoring it to your needs in our guides:

  • Developer guide: Contributing to cipjs-unit, writing coverage, and updates.

Help Out

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

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

We communicate via issues and pull requests.

For any issues or questions, please join our Discord server for support. Our community and support team are available to assist you with any problems you may face.


Copyright © 2024