@0xcert/ethereum-utils
Advanced tools
Comparing version 1.1.0 to 1.2.0-alpha1
{ | ||
"name": "@0xcert/ethereum-utils", | ||
"version": "1.1.0", | ||
"description": "Common utilities for the Ethereum blockchain.", | ||
"main": "truffle.js", | ||
"directories": { | ||
"contracts": "contracts", | ||
"migrations": "migrations", | ||
"test": "test" | ||
}, | ||
"version": "1.2.0-alpha1", | ||
"description": "General Ethereum utility module with helper functions for the Ethereum blockchain.", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"clean": "rm -Rf ./build", | ||
"compile": "truffle compile", | ||
"console": "truffle console", | ||
"flatten": "mkdir -p build && truffle-flattener contracts/**/*.sol >> build/bundle.sol", | ||
"lint": "eslint './**/*.js?(x)'", | ||
"migrate": "truffle migrate", | ||
"networks": "truffle networks", | ||
"postpublish": "npm run clean", | ||
"prepublish": "npm run compile", | ||
"test": "npm run clean && truffle test" | ||
"build": "npm run clean && npx tsc", | ||
"clean": "rm -Rf ./dist", | ||
"lint": "npx tslint 'src/**/*.ts?(x)'", | ||
"test": "npm run lint && npx nyc npx hayspec test" | ||
}, | ||
"author": "0xcert", | ||
"license": "MIT", | ||
"hayspec": { | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"match": [ | ||
"./src/tests/**/*.test.ts" | ||
] | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"exclude": [ | ||
"src/tests" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/0xcert/ethereum-utils.git" | ||
"url": "git+https://github.com/0xcert/framework.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/0xcert/ethereum-utils/issues" | ||
"url": "https://github.com/0xcert/framework/issues" | ||
}, | ||
"homepage": "https://github.com/0xcert/ethereum-utils#readme", | ||
"homepage": "https://github.com/0xcert/framework#readme", | ||
"keywords": [ | ||
"ethereum", | ||
"0xcert", | ||
"framework", | ||
"protocol", | ||
"asset", | ||
"value", | ||
"values", | ||
"currency", | ||
"token", | ||
"non-fungible", | ||
"fungible", | ||
"erc-721", | ||
"erc-20", | ||
"blockchain", | ||
"eth", | ||
"contract", | ||
"contracts", | ||
"smart", | ||
"javascript", | ||
"typescript", | ||
"nodejs", | ||
"vuejs", | ||
"nuxtjs", | ||
"npm", | ||
"libraries", | ||
"smart-contract", | ||
"smart-contracts", | ||
"token", | ||
"tokens", | ||
"utils", | ||
"utility", | ||
"utilities" | ||
"ethereum", | ||
"zxc" | ||
], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^4.19.1", | ||
"truffle": "^4.1.11", | ||
"truffle-flattener": "^1.2.5" | ||
"@hayspec/cli": "^0.8.3", | ||
"@hayspec/spec": "^0.8.3", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.12.1", | ||
"typescript": "^3.1.1" | ||
}, | ||
"dependencies": { | ||
"ethers": "4.0.0-beta.1" | ||
} | ||
} |
@@ -1,33 +0,74 @@ | ||
<img src="https://github.com/0xcert/ethereum-utils/raw/master/assets/cover.png" /> | ||
<img src="https://github.com/0xcert/framework/raw/master/assets/cover-sub.png" /> | ||
![Build Status](https://travis-ci.org/0xcert/ethereum-utils.svg?branch=master) [![NPM Version](https://badge.fury.io/js/@0xcert%2Fethereum-utils.svg)](https://badge.fury.io/js/0xcert%2Fethereum-utils) [![Dependencies Status](https://david-dm.org/0xcert/ethereum-utils.svg)](https://david-dm.org/0xcert/ethereum-utils) | ||
> General Ethereum utility module with helper functions for the Ethereum blockchain. | ||
> Common utilities for the Ethereum blockchain. | ||
The [0xcert Framework](https://docs.0xcert.org) is a free and open-source JavaScript library that provides tools for building powerful decentralized applications. Please refer to the [official documentation](https://docs.0xcert.org) for more details. | ||
This is an open source project build with [Truffle](http://truffleframework.com) framework. It provides common helper contracts that we can use as [Truffle modules](http://truffleframework.com/docs/getting_started/packages-npm) in other [Truffle](http://truffleframework.com) projects. | ||
This module is one of the bricks of the [0xcert Framework](https://docs.0xcert.org). It's written with [TypeScript](https://www.typescriptlang.org) and it's actively maintained. The source code is available on [GitHub](https://github.com/0xcert/framework) where you can also find our [issue tracker](https://github.com/0xcert/framework/issues). | ||
## Structure | ||
# Ethereum Utilities | ||
Since this is a Truffle project, you will find all contracts in `contracts` directory. | ||
This module wraps several useful Ethereum functions which will be useful through the 0xcert Framework. Currently supported are these functions and classes from [ethers.js](https://github.com/ethers-io/ethers.js): | ||
## Installation | ||
## ABI coder | ||
Requirements: | ||
- NodeJS 9.0+ recommended. | ||
- Windows, Linux or Mac OS X. | ||
This converts value to and from the packed [Ethereum ABI encoding](https://solidity.readthedocs.io/en/develop/abi-spec.html#formal-specification-of-the-encoding). | ||
### NPM | ||
* `encodeParameters`(types: `any`, values: `Array<any>`): `string` | ||
* `decodeParameters`(types: `any`, data: `any`): `any` | ||
This is an [NPM](https://www.npmjs.com/package/@0xcert/ethereum-utils) module for [Truffle](http://truffleframework.com) framework. In order to use it as a dependency in your Javascript project, you must first install it through the `npm` command: | ||
**Encoding example:** | ||
```ts | ||
import { decodeParameters, encodeParameters } from '0xcert/ethereum-utils/abi'; | ||
const types = ['tuple(uint256, uint256[])']; | ||
const values = [[ 42, [ 45 ] ]]; | ||
const encodedValues = encodeParameters(types, values); | ||
``` | ||
$ npm install @0xcert/ethereum-utils | ||
**Decoding example:** | ||
```ts | ||
import { decodeParameters, encodeParameters } from '0xcert/ethereum-utils/abi'; | ||
const types = ['tuple(uint256, uint256[])']; | ||
const encoded = '0x' + | ||
'0000000000000000000000000000000000000000000000000000000000000020' + | ||
'000000000000000000000000000000000000000000000000000000000000002a' + | ||
'0000000000000000000000000000000000000000000000000000000000000040' + | ||
'0000000000000000000000000000000000000000000000000000000000000001' + | ||
'000000000000000000000000000000000000000000000000000000000000002d'; | ||
const values = decodeParameters(types, values); | ||
``` | ||
## Contributing | ||
## BigNumber and bigNumberify | ||
See [CONTRIBUTING.md](./CONTRIBUTING.md) for how to help out. | ||
Here is a basic example adapted from [the ethers.js documentation](https://docs.ethers.io/ethers.js/html/api-utils.html?highlight=bignumberify#big-numbers). | ||
## Licence | ||
```ts | ||
import { BigNumber, bigNumberify } from '0xcert/ethereum-utils/big-number'; | ||
See [LICENSE](./LICENSE) for details. | ||
let gasPriceWei = bigNumberify("20902747399"); | ||
let gasLimit = bigNumberify(3000000); | ||
let maxCostWei = gasPriceWei.mul(gasLimit) | ||
console.log("Max Cost: " + maxCostWei.toString()); | ||
// "Max Cost: 62708242197000000" | ||
console.log("Number: " + maxCostWei.toNumber()); | ||
// throws an Error, the value is too large for JavaScript to handle safely | ||
``` | ||
## Address normalization | ||
The ethers.js [address normalization function](https://docs.ethers.io/ethers.js/html/api-utils.html?highlight=getaddress#addresses) implements [EIP-55 Mixed-case checksum address encoding](https://eips.ethereum.org/EIPS/eip-55). | ||
```ts | ||
import { getAddress } from '0xcert/ethereum-utils/normalize-address'; | ||
let zxcTokenAddress = '0x83e2be8d114f9661221384b3a50d24b96a5653f5'; | ||
let zxcTokenAddressNormalized = normalizeAddress(zxcToenAddress); | ||
// 0x83e2BE8d114F9661221384B3a50d24B96a5653F5 | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
40
74
30300
1
5
566
1
1
1
+ Addedethers@4.0.0-beta.1
+ Added@types/node@10.17.60(transitive)
+ Addedaes-js@3.0.0(transitive)
+ Addedbn.js@4.12.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedelliptic@6.3.3(transitive)
+ Addedethers@4.0.0-beta.1(transitive)
+ Addedhash.js@1.1.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjs-sha3@0.5.7(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedscrypt-js@2.0.3(transitive)
+ Addedsetimmediate@1.0.4(transitive)
+ Addeduuid@2.0.1(transitive)
+ Addedxmlhttprequest@1.8.0(transitive)