Git Product home page Git Product logo

libtx's Introduction

Build Status Coverage Status

Transact

This library converts human readable data structures to and from the binary structures required by the blockchain. This package does serialization and deserialization only, if you need fully functional transactions your better off using the eosjs package.

Warning: This API is still changing. I may force push changes..

API

const assert = require('assert')
const Tx = require('.')//eosjs-libtx

// ### General Use Case

// Warning: Do not use {defaults: true} in production
const tx = Tx({defaults: true})
assert(tx.errors.length === 0, tx.errors)
const {Message} = tx.structs

// Message (see https://github.com/eosjs/json/blob/master/operations.json)
Message.toObject()
// Output: { from: '', to: '', cc: [ '' ], type: '', data: '' }

// Convert JSON into a binary buffer
const msg = Message.fromObject({ from: 'jc', to: 'charles', cc: [ 'abc' ], type: '', data: '0f0f0f' })
const msgBuf = Tx.toBuffer(Message, msg)
// toBuffer returns: <Buffer 02 6a 63 07 63 68 61 72 6c 65 73 01 03 61 62 63 00 03 0f 0f 0f>

const obj = Message.toObject(Tx.fromBuffer(Message, msgBuf))
assert.deepEqual(Message.toObject(msg), obj)


// ### Smart contracts may extend and define their own data-structures (see ./index.test.js for more)

const myTx = tx.extend({
    TimedPermission: {base: 'AccountPermission', fields: {expires: 'Time'}}
})
assert(myTx.errors.length === 0, myTx.errors)
const {TimedPermission} = myTx.structs
TimedPermission.toObject()
// toObject returns: { account: '', permission: '', expires: '1970-01-01T00:00:00Z' }

Environment

ECMAScript 6 (ES6)

libtx's People

Contributors

iriberri avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.