Announcing 0x.js

Official JavaScript Library for 0x Protocol

Launching a decentralized exchange on the Ethereum blockchain is a significant undertaking. Among other challenges, one must be able to:

Write efficient, secure Ethereum smart contracts. Hook into these contracts from a client-side web application. Host an off-chain order book and serve it to clients. Provide a clean user experience on the frontend.

When 0x protocol’s open source and publicly accessible smart contracts are deployed to the Ethereum blockchain in August, they will offer a complete solution to (1). Today, we are excited to announce 0x.js which should go a long way towards solving (2).

0x.js Technical Overview

0x.js is an open source JavaScript library (GitHub) that provides much of the functionality needed to build a web application on top of 0x protocol. The ZeroEx class contains all of the library’s functionality, which is organized according to smart contract:

Exchange: generate, cryptographically sign, fill and cancel orders, authenticate order signatures.

Token: query/transfer ERC20 token balances, query/approve/transferFrom token allowances.

TokenRegistry: query token metadata from a verified source.

EtherToken: convert between ether and ERC20 compliant ether tokens.

Proxy: query versions of the Exchange contract.

Since 0x.js has not yet hit version 1.0, we expect that there will be frequent changes to its public interface. We therefore put together a versioned documentation page that documents every released version of 0x.js. You can start developing on 0x today knowing that the documentation for any particular version of 0x.js you are using will always be available.

Type Safety

When building an application that handles digital assets, it is critical that user inputs are verified as strictly as possible. What may seem like an insignificant detail can result in the loss or theft of millions of dollars. We value security and productivity, that’s why we’ve written 0x.js in TypeScript and all of the 0x.js types are available for TypeScript users out of the box. If you are not a TypeScript user, you still gain the benefits of type safety in your JavaScript app. All public functions validate passed in arguments and throw a helpful error message if any arguments are found to be invalid.

All Ethereum addresses must be hex encoded 40 character byte strings. Here, a detailed error message is thrown when the “maker” argument does not match the required data type.

Promise Based

0x.js is a promise based library, which eliminates the perils of callback hell and makes it possible to use the ES7 async/await syntax:

Asynchronous code never looked so good.

Future Improvements

0x.js is a work in progress. In the near term, we eagerly await the v1.0 release of web3.js and the associated support for web sockets. We also plan on simplifying the process of monitoring the mempool, analyzing pending transactions, handling block/log removals from chain reorganizations and block/log backfills on skipped blocks using something like Micah Zoltu’s ethereumjs-blockstream. Feel free to contribute ideas and submit issues to our GitHub or reach out to us on Gitter.

Upcoming Hackathon: 0xHack

Are you a hard working developer looking for an opportunity to break into the Ethereum space? 0xHack is for you. Prove yourself by building a prototype application on top of 0x protocol targeting one of numerous verticals during a one week long hackathon in September. Standout individuals and teams will have the opportunity to receive seed funding, introductions to top VC firms, ZRX tokens and even job opportunities. We will release details about 0xHack soon.

You can keep up to date with 0x developments by joining our Discord Chat.