What is ethjs-util?
The ethjs-util package provides a collection of utility functions for Ethereum-related operations. These utilities include functions for handling hex strings, checking types, and manipulating buffers, among others.
What are ethjs-util's main functionalities?
Hex String Conversion
This feature allows you to convert a buffer to a hex string. The code sample demonstrates converting the string 'hello' into its hex representation.
const ethUtil = require('ethjs-util');
const hexString = ethUtil.bufferToHex(Buffer.from('hello', 'utf8'));
console.log(hexString); // '0x68656c6c6f'
Type Checking
This feature provides functions to check if a given string is a valid hex string. The code sample checks if '0x68656c6c6f' is a hex string.
const ethUtil = require('ethjs-util');
const isHex = ethUtil.isHexString('0x68656c6c6f');
console.log(isHex); // true
Buffer Manipulation
This feature includes functions for manipulating buffers, such as setting their length. The code sample demonstrates padding a buffer to a specified length.
const ethUtil = require('ethjs-util');
const buffer = ethUtil.setLengthLeft(Buffer.from('1234', 'utf8'), 10);
console.log(buffer); // <Buffer 00 00 00 00 00 00 31 32 33 34>
Other packages similar to ethjs-util
ethereumjs-util
The ethereumjs-util package offers a comprehensive set of utility functions for Ethereum, similar to ethjs-util. It includes additional features like keccak256 hashing and RLP encoding/decoding, making it more versatile for Ethereum development.
web3-utils
The web3-utils package is part of the Web3.js library and provides utility functions for Ethereum dApp development. It includes functions for hex string manipulation, type checking, and more, similar to ethjs-util, but is more tightly integrated with the Web3.js ecosystem.
ethers-utils
The ethers-utils package is part of the ethers.js library and offers a wide range of utility functions for Ethereum. It provides similar functionalities to ethjs-util, such as hex string conversion and type checking, but also includes additional features like ABI encoding/decoding and ENS name resolution.
ethjs-util
A simple set of Ethereum JS utilities such as toBuffer
and isHexPrefixed
.
Install
npm install --save ethjs-util
Usage
const util = require('ethjs-util');
const value = util.intToBuffer(38272);
About
A simple set of Ethereum JS utilties, mainly for frontend dApps.
Available Methods
arrayContainsArray
getBinarySize
toBuffer
intToBuffer
getBinarySize
isHexPrefixed
stripHexPrefix
padToEven
intToHex
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:
- Improve documentation.
- Chime in on any open issue or pull request.
- Open new issues about your ideas for making stylelint better, and pull requests to show us how your idea works.
- Add new tests to absolutely anything.
- Create or contribute to ecosystem tools, like the plugins for Atom and Sublime Text.
- 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.