All Projects → ethereumjs → Ethereumjs Abi

ethereumjs / Ethereumjs Abi

Licence: mit
[DEPRECATED] Decoder and encoder for the Ethereum ABI

Programming Languages

javascript
184084 projects - #8 most used programming language
solidity
1140 projects

Projects that are alternatives of or similar to Ethereumjs Abi

Core Geth
A highly configurable Go implementation of the Ethereum protocol.
Stars: ✭ 66 (-71.91%)
Mutual labels:  rpc, ethereum
Chainabstractionlayer
Blockchain abstraction layer
Stars: ✭ 131 (-44.26%)
Mutual labels:  rpc, ethereum
Nethereum
Ethereum .Net cross platform integration library
Stars: ✭ 1,191 (+406.81%)
Mutual labels:  rpc, ethereum
Spyne
A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
Stars: ✭ 992 (+322.13%)
Mutual labels:  rpc, json
Jsonrpc
The jsonrpc package helps implement of JSON-RPC 2.0
Stars: ✭ 143 (-39.15%)
Mutual labels:  rpc, json
Wheel
关于net nio os cache db rpc json web http udp tcp mq 等多个小工具的自定义实现
Stars: ✭ 45 (-80.85%)
Mutual labels:  rpc, json
Rpc.py
A fast and powerful RPC framework based on ASGI/WSGI.
Stars: ✭ 98 (-58.3%)
Mutual labels:  rpc, json
Webrpc
webrpc is a schema-driven approach to writing backend services for modern Web apps and networks
Stars: ✭ 342 (+45.53%)
Mutual labels:  rpc, json
Autocser
AutoCSer is a high-performance RPC framework. AutoCSer 是一个以高效率为目标向导的整体开发框架。主要包括 TCP 接口服务框架、TCP 函数服务框架、远程表达式链组件、前后端一体 WEB 视图框架、ORM 内存索引缓存框架、日志流内存数据库缓存组件、消息队列组件、二进制 / JSON / XML 数据序列化 等一系列无缝集成的高性能组件。
Stars: ✭ 140 (-40.43%)
Mutual labels:  rpc, json
Noproto
Flexible, Fast & Compact Serialization with RPC
Stars: ✭ 138 (-41.28%)
Mutual labels:  rpc, json
Libjson Rpc Cpp
C++ framework for json-rpc (json remote procedure call)
Stars: ✭ 653 (+177.87%)
Mutual labels:  rpc, json
Co
Art of C++. Flag, logging, unit-test, json, go-style coroutine and more.
Stars: ✭ 2,264 (+863.4%)
Mutual labels:  rpc, json
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+126.38%)
Mutual labels:  rpc, json
Jsmnsol
A JSON parser for solidity
Stars: ✭ 56 (-76.17%)
Mutual labels:  ethereum, json
Airframe
Essential Building Blocks for Scala
Stars: ✭ 442 (+88.09%)
Mutual labels:  rpc, json
Coin registry
A global registry of JSON formatted files on 1500+ cryptocurrency tokens. Provides information like chat rooms, communities, explorers, and contact information on each coin. Used by https://blockmodo.com, DEXs, developers, and exchanges.
Stars: ✭ 85 (-63.83%)
Mutual labels:  ethereum, json
Bebop
An extremely simple, fast, efficient, cross-platform serialization format
Stars: ✭ 305 (+29.79%)
Mutual labels:  rpc, json
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (-43.83%)
Mutual labels:  rpc, json
Ti Rpc
基于swoole封装的一个简易的JSON协议的RPC框架,思路是借鉴的,代码是自己写的。小修小改的,目前服务于前公司(注意是前公司)生产环境,每日支撑大约8000万次调用。
Stars: ✭ 144 (-38.72%)
Mutual labels:  rpc, json
Dop
JavaScript implementation for Distributed Object Protocol
Stars: ✭ 163 (-30.64%)
Mutual labels:  rpc, json

This library is deprecated and will not be further maintained. It specifically doesn't support the new ABI v2 which is now activated as the default ABI encoder starting with Solidity v0.8.0 released in December 2020.

We recommend to use the Ethers.js v5 ABI Encoder as a replacement which supports the new ABI v2 standard and is under active development.


ethereumjs-abi

NPM Package Build Status Coverage Status js-standard-style Discord

Module implementing the Ethereum ABI in Javascript. Can be used with RPC libraries for communication or with ethereumjs-vm to implement a fully fledged simulator.

Usage

Manual encoding and decoding

There are three methods of interest:

  • methodID to create a function signature
  • rawEncode to encode fields and
  • rawDecode to decode fields

Example code:

var abi = require('ethereumjs-abi')

// returns the encoded binary (as a Buffer) data to be sent
var encoded = abi.rawEncode([ "address" ], [ "0x0000000000000000000000000000000000000000" ])

// returns the decoded array of arguments
var decoded = abi.rawDecode([ "address" ], data)

Encoding and decoding aided by the JSON ABI definition

Planned for the future is supporting the JSON ABI definition:

var abi = require('ethereumjs-abi')

// need to have the ABI definition in JSON as per specification
var tokenAbi = [{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"type":"function"},{"inputs":[],"type":"constructor"}]

var encoded = abi.encode(tokenAbi, "balanceOf(uint256 address)", [ "0x0000000000000000000000000000000000000000" ])

var decoded = abi.decode(tokenAbi, "balanceOf(uint256 address)", data)

Simple encoding and decoding

var abi = require('ethereumjs-abi')

// returns the encoded binary (as a Buffer) data to be sent
var encoded = abi.simpleEncode("balanceOf(address):(uint256)", "0x0000000000000000000000000000000000000000")

// returns the decoded array of arguments
var decoded = abi.simpleDecode("balanceOf(address):(uint256)", data)

Solidity tightly packed formats

This library also supports creating Solidity's tightly packed data constructs, which are used together with sha3, sha256 and ripemd160 to create hashes.

Solidity code:

contract HashTest {
  function testSha3() returns (bytes32) {
   address addr1 = 0x43989fb883ba8111221e89123897538475893837;
   address addr2 = 0;
   uint val = 10000;
   uint timestamp = 1448075779;

   return sha3(addr1, addr2, val, timestamp); // will return 0xc3ab5ca31a013757f26a88561f0ff5057a97dfcc33f43d6b479abc3ac2d1d595
 }
}

Creating the same hash using this library:

var abi = require('ethereumjs-abi')
var BN = require('bn.js')

abi.soliditySHA3(
    [ "address", "address", "uint", "uint" ],
    [ new BN("43989fb883ba8111221e89123897538475893837", 16), 0, 10000, 1448075779 ]
).toString('hex')

For the same data structure:

  • sha3 will return 0xc3ab5ca31a013757f26a88561f0ff5057a97dfcc33f43d6b479abc3ac2d1d595
  • sha256 will return 0x344d8cb0711672efbdfe991f35943847c1058e1ecf515ff63ad936b91fd16231
  • ripemd160 will return 0x000000000000000000000000a398cc72490f72048efa52c4e92067e8499672e7 (NOTE: it is 160bits, left padded to 256bits)

Note that ripemd160() in Solidity returns bytes20 and if you cast it to bytes32, it will be right padded with zeroes.

Using Serpent types

Serpent uses a different notation for the types, even though it will serialize to the same ABI.

We provide two helpers to convert between these notations:

  • fromSerpent: convert a Serpent notation to the ABI notation
  • toSerpent: the other way around

Example usage:

abi.fromSerpent('s')    // [ 'bytes' ]
abi.fromSerpent('i')    // [ 'int256' ]
abi.fromSerpent('a')    // [ 'int256[]' ]
abi.fromSerpent('b8')   // [ 'bytes8' ]
abi.fromSerpent('b8i')  // [ 'bytes8', 'int256' ]

abi.toSerpent([ 'bytes' ])             // 's'
abi.toSerpent([ 'int256' ])            // 'i'
abi.toSerpent([ 'int256[]' ])          // 'a'
abi.toSerpent([ 'bytes8' ])            // 'b8'
abi.toSerpent([ 'bytes8', 'int256' ])  // 'b8i'

It is to be used in conjunction with rawEncode and rawDecode:

var encoded = abi.rawEncode(abi.fromSerpent("i"), [ "0x0000000000000000000000000000000000000000" ])

var decoded = abi.rawDecode([...abi.fromSerpent("i"), ...abi.fromSerpent("i")], data)

Note: Serpent uses arbitary binary fields. If you want to store strings it is preferable to ensure it is stored as UTF8. Buffer.from(<string>, 'utf8') can be used to ensure it is properly encoded.

Contributing

I am more than happy to receive improvements. Please send me a pull request or reach out on email or twitter.

There is a lot missing, grep for FIXME in the source code to find inspiration.

EthereumJS

See our organizational documentation for an introduction to EthereumJS as well as information on current standards and best practices.

If you want to join for work or do improvements on the libraries have a look at our contribution guidelines.

License

Copyright (C) 2015 Alex Beregszaszi

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].