To get a local development version of 0x-api running:
-
Clone the repo.
-
Create an
.envfile and copy the content from the.env_examplefile. Defaults are defined inconfig.ts/config.js. The bash environment takes precedence over the.envfile. If you runsource .env, changes to the.envfile will have no effect until you unset the colliding variables.
| Environment Variable | Default | Description |
|---|---|---|
CHAIN_ID |
Required. No default. | The chain id you'd like your API to run on (e.g: 1 -> mainnet, 42 -> Kovan, 3 -> Ropsten, 1337 -> Ganache). Defaults to 42 in the API, but required for docker-compose up. |
ETHEREUM_RPC_URL |
Required. No default. | The URL used to issue JSON RPC requests. Use http://ganache:8545 to use the local ganache instance. |
MESH_WEBSOCKET_URI |
Required. Default for dev: ws://localhost:60557 |
The URL pointing to the 0x Mesh node. A default node is spun up in docker-compose up |
POSTGRES_URI |
Required. Default for dev: postgresql://api:api@localhost/api |
A URI of a running postgres instance. By default, the API will create all necessary tables. A default instance is spun up in docker-compose up |
FEE_RECIPIENT_ADDRESS |
0x0000000000000000000000000000000000000000 |
The Ethereum address which should be specified as the fee recipient in orders your API accepts. |
MAKER_FEE_ASSET_DATA |
0x |
The maker fee token asset data for created 0x orders. |
TAKER_FEE_ASSET_DATA |
0x |
The taker fee token asset data for created 0x orders. |
MAKER_FEE_UNIT_AMOUNT |
0 |
The flat maker fee amount you'd like to receive for filled orders hosted by you. |
TAKER_FEE_UNIT_AMOUNT |
0 |
The flat taker fee amount you'd like to receive for filled orders hosted by you. |
WHITELIST_ALL_TOKENS |
false |
A boolean determining whether all tokens should be allowed to be posted. |
-
Install the dependencies:
yarn
-
Build the project:
yarn build
-
Run
docker-compose upto run the other dependencies required for the API. This uses the localdocker-compose.ymlfile. On start-up, the event-pipeline container will crash and restart until Postgres is up. If you switchCHAIN_IDafter a prior run, you will have torm -rf 0x_mesh postgresto delete the volumes containing stale data. -
Start the API
yarn start
For development:
yarn dev
Set the environment variables CHAIN_ID=1337 and ETHEREUM_RPC_URL=http://ganache:8545. Run docker-compose up and wait for containers to start up.
Then run yarn test.
yarn build- Build the codeyarn test- Test the code (must run docker-compose first)yarn lint- Lint the codeyarn start- Starts the APIyarn dev- Starts the API in dev-modeyarn watch- Watch the source code and rebuild on changeyarn prettier- Auto-format the code
A Docker image is built and hosted by Dockerhub every time a change to the master branch occurs.
Running this image will run 0x API as a monolith, with all it's dependencies. With some minor configuration and refactoring, you can run the different components of the API separately.
This project uses TypeORM. It makes it easier for anyone to switch out the backing database used by this project. By default, this project uses a PostgreSQL database.
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
