Table of contents
- Getting started
- Legal Disclaimer
The 0x API is a collection of services and endpoints that can be run together or separately. In aggregate, the APIs provide interfaces to 0x liquidity.
Everything can be run monolithically via
yarn start and
docker-compose up as described in Getting Started.
The API contains different services that serve a collection of HTTP or websocket endpoints and keep your order states in sync with the Ethereum state.
These are services that handle HTTP requests and responses.
|Name||Path||Run Command||Requires Ethereum JSON RPC Provider?||Requires Relational Database?|
|All HTTP Services||
|Meta Transaction Service||
The transaction watcher ensures that the data being served is present and up-to-date by keeping the database in sync with Ethereum. The endpoints above run without it, but would be providing degraded or non-functional service.
|Name||Run Command||Requires Ethereum JSON RPC Provider?||Requires Relational Database?|
|Transaction Watcher (monitor and broadcast meta transactions)||
To get a local development version of
Clone the repo.
.envfile and copy the content from the
.env_examplefile. Defaults are defined in
config.js. The bash environment takes precedence over the
.envfile. If you run
source .env, changes to the
.envfile will have no effect until you unset the colliding variables.
||Required. No default.||The chain id you'd like your API to run on (e.g:
||Required. No default.||The URL used to issue JSON RPC requests. Use
||The URL used to fetch gas prices. It should be changed to a matching endpoint based on
||Required. Default for dev:
||A URI of a running postgres instance. By default, the API will create all necessary tables. A default instance is spun up in
||Optional. No default||A comma separated list of URIs of running postgres read replica instances.|
||The Ethereum address which should be specified as the fee recipient in orders your API accepts.|
||The maker fee token asset data for created 0x orders.|
||The taker fee token asset data for created 0x orders.|
||The flat maker fee amount you'd like to receive for filled orders hosted by you.|
||The flat taker fee amount you'd like to receive for filled orders hosted by you.|
||A boolean determining whether all tokens should be allowed to be posted.|
||A comma separated list of addresses to ignore. These addresses are persisted but not used in any
||A comma separated list of whitelisted 0x API keys that can use the meta-txn /submit endpoint.|
||A comma separated list of meta-txn relay sender private keys managed by the TransactionWatcherSignerService.|
||A boolean determining whether the meta-txn signs and submits transactions .|
||The maximum gas price (in gwei) the meta-txn service will submit a transaction at. If the gas price of the network exceeds this value then the meta-txn service will be disabled.|
||The expected time for a meta-txn to be included in a block.|
||A boolean determining whether to enable prometheus monitoring.|
||The port from which prometheus metrics should be served.|
||Optional. No default.||A comma separated list of Kafka broker servers|
||Optional. No default||The name of the Kafka topic to publish quote reports on. Setting this and
Install the dependencies:
Build the project:
docker-compose upto run the other dependencies required for the API. This uses the local
Run the database migrations:
Start the API
Adding a new contract
NOTE: This repo is undergoing a tooling change.
To add a new contract, you will need to add it to
You can generate the entire list by running the following:
find . -type f -name "*.sol" | grep -v foundry | grep -v "contracts/lib" | grep -v "node_modules"
Developing on Ganache
To use ganache, use the
.env file below:
$ docker-compose up $ yarn dev
Developing on Foundry
Install Foundry if needed.
Initialize git submodule:
git submodule update --init --recursive
cd contracts forge build
yarn test. It's really that easy :)
Tip: Test suites set up and teardown sandboxed environments, so using
describe statements will save lots of development time.
yarn build- Build the code
yarn test- Test the code
yarn lint- Lint the code
yarn start- Starts the API
yarn dev- Starts the API in dev-mode
yarn watch- Watch the source code and rebuild on change
yarn prettier- Auto-format the code
yarn release- Release a new version of the 0x-api
A Docker image is built and hosted by Dockerhub every time a change to the
master branch occurs. A Docker image is built, pushed and tagged when a new version is released as well.
Running this image will run 0x API as a monolith, with all its dependencies. You can run any of the services separately by overriding the Docker command with the service-specific command when running the container.
When versioning the API, we freeze the old version in a separate branch so that we can deploy patches, and continue to support the old version until it's officially deprecated. Be aware when contributing fixes that you may want to apply the fix to an older version too.
This is a list of endpoints supported by different versions of the API. If an endpoint is not on this list, it is by default pointed to the master branch.
|Endpoint(s)||API version branch||@0x/asset-swapper branch|
To add a migration, you may use the following command:
yarn db:migration:create -n myMigration
The laws and regulations applicable to the use and exchange of digital assets and blockchain-native tokens, including through any software developed using the licensed work created by ZeroEx Intl. as described here (the “Work”), vary by jurisdiction. As set forth in the Apache License, Version 2.0 applicable to the Work, developers are “solely responsible for determining the appropriateness of using or redistributing the Work,” which includes responsibility for ensuring compliance with any such applicable laws and regulations. See the Apache License, Version 2.0 for the specific language governing all applicable permissions and limitations: http://www.apache.org/licenses/LICENSE-2.0