ABI encoder for Serpent contracts
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist Added BigNumber element support to bytes-to-utf16 conversion Jan 14, 2017
scripts refactored indentation to 2 spaces Jan 12, 2017
test
.gitignore Split from augur.js Aug 21, 2015
.jshintrc refactored indentation to 2 spaces Jan 12, 2017
.npmignore Split from augur.js Aug 21, 2015
.travis.yml Added BigNumber element support to bytes-to-utf16 conversion Jan 14, 2017
README.md Added initial error checks to fix, unfix, bignum Sep 10, 2015
exports.js Split from augur.js Aug 21, 2015
gulpfile.js refactored indentation to 2 spaces Jan 12, 2017
index.js Added BigNumber element support to bytes-to-utf16 conversion Jan 14, 2017
package.json Added BigNumber element support to bytes-to-utf16 conversion Jan 14, 2017

README.md

augur-abi

Build Status Coverage Status npm version

augur-abi is a standalone JavaScript module that provides Ethereum contract ABI data serialization methods. ABI encoding is needed to invoke functions on Ethereum smart contracts.

This module presently supports only Serpent contracts; it's my intention to add Solidity data type support when I have time!

Installation

$ npm install augur-abi

Usage

To use augur-abi in Node.js, just require it:

var augur_abi = require("augur-abi");

A minified, browserified file dist/augur-abi.min.js is included for use in the browser. Including this file simply attaches the augur_abi object to window:

<script src="dist/augur-abi.min.js" type="text/javascript"></script>

The encode method encodes the full ABI data (prefix + parameters) needed for a contract function call. For example, to encode a method named double that takes a single integer parameter with a value of 3:

var encoded = augur_abi.encode({
    method: "double",
    signature: "i",
    params: [3]
});
// encoded:
'0x6ffa1caa0000000000000000000000000000000000000000000000000000000000000003'

encoded is the concatenation of the method's prefix 0x6ffa1caa, which is derived from the name of the method "double" and its signature "i", and the encoded parameter value, [3].

"Signature" refers to the short-form Serpent parameter signature, which allows i (int256), a (variable-sized int256 array) and s (variable-length string/bytes). For example, a method which takes parameter types int256, string, int256, int256, int256, array would have signature isiiia.

Tests

Unit tests are in the test directory, and can be run with mocha:

$ npm test