开发者社区> 镜像站> NPM> ethjs-abi
ethjs-abi
Just the Ethereum encoding and decoding methods from the ethers-io-wallet.
Last updated 3 years ago by silentcicero .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ethjs-abi 
SYNC missed versions from official npm registry.

ethjs-abi

Just method and event encoding and decoding from the ethers-wallet.

Note, this package is experimental, and is not ready for production use.

Dependency Status devDependency Status Build Status NPM version Test Coverage js-airbnb-style

Usage

const abi = require('ethjs-abi');
const SimpleStoreABI = [{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"set","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"get","outputs":[{"name":"storeValue","type":"uint256"}],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newValue","type":"uint256"},{"indexed":false,"name":"_sender","type":"address"}],"name":"SetComplete","type":"event"}];


const setInputBytecode = abi.encodeMethod(SimpleStoreABI[0], [24000]);

// returns 0x60fe47b10000000000000000000000000000000000000000000000000000000000005dc0

const setOutputBytecode = abi.decodeMethod(SimpleStoreABI[0], "0x0000000000000000000000000000000000000000000000000000000000000001");

// returns  Result { '0': true }



const getInputBytecode = abi.encodeMethod(SimpleStoreABI[1], []);

// returns 0x6d4ce63c

const getMethodOutputBytecode = abi.decodeMethod(SimpleStoreABI[1], "0x000000000000000000000000000000000000000000000000000000000000b26e");

// returns Result { '0': <BN: b26e>, storeValue: <BN: b26e> }



const SetCompleteInputBytecode = abi.encodeEvent(SimpleStoreABI[2], [24000, "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"]);

// returns 0x10e8e9bc0000000000000000000000000000000000000000000000000000000000005dc0000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c

const SetCompleteOutputBytecode = abi.decodeEvent(SimpleStoreABI[2], "0x0000000000000000000000000000000000000000000000000000000000000d7d000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c", ["0xc36800ebd6079fdafc3a7100d0d1172815751804a6d1b7eb365b85f6c9c80e61"]);

/* returns   Result {
  '0': <BN: d7d>,
  '1': '0xca35b7d915458ef540ade6068dfe2f44e8fa733c',
  _newValue: <BN: d7d>,
  _sender: '0xca35b7d915458ef540ade6068dfe2f44e8fa733c' }
*/

const methodSig = abi.encodeSignature(SimpleStoreABI[2]);

/* returns 0x10e8e9bc */

for contract SimpleStore:

pragma solidity ^0.4.4;

contract SimpleStore {
  uint store;

  function set(uint256 _value) returns (bool) {
    store = _value;

    SetComplete(store, msg.sender);

    return true;
  }

  function get() returns (uint256 storeValue) {
    return store;
  }

  event SetComplete(uint256 _newValue, address _sender);
}

About

Just the encoding and decoding of contract data.

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.

Guides

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

  • User guide - Usage, configuration, FAQ and complementary tools.
  • Developer guide - Contributing to ethjs-abi and writing your own code and coverage.

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:

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

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.

Original Port Author

Richard Moore me@ricmoo.com

Current Tags

  • 0.2.1                                ...           latest (3 years ago)

12 Versions

  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.9                                ...           4 years ago
  • 0.1.8                                ...           4 years ago
  • 0.1.7                                ...           4 years ago
  • 0.1.6                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 1
This Week 147
This Month 133
Last Day 23
Last Week 123
Last Month 407
Dependencies (3)
Dev Dependencies (49)
Dependents (97)