0x Mesh
Search…
Deployment guide

0x Mesh Deployment Guide

Welcome to the 0x Mesh Deployment Guide! This guide will walk you through how to configure and deploy your own 0x Mesh node.

Supported Chains

Enabling Telemetry

You can optionally help us develop and maintain Mesh by automatically sending your logs, which requires a few extra steps. If you are interested in enabling telemetry, check out this guide.

Running Mesh

Make sure you have Docker installed. Then run:
1
docker run \
2
--restart unless-stopped \
3
-p 60558:60558 \
4
-p 60559:60559 \
5
-e ETHEREUM_CHAIN_ID="1" \
6
-e ETHEREUM_RPC_URL="{your_ethereum_rpc_url}" \
7
-e VERBOSITY=5 \
8
-v {local_path_on_host_machine}/0x_mesh:/usr/mesh/0x_mesh \
9
0xorg/mesh:{version}
Copied!
  1. 1.
    Replace {your_ethereum_rpc_url} with the RPC endpoint for an Ethereum node (e.g. Infura or Alchemy).
  2. 2.
    Replace and {local_path_on_host_machine} with a directory on your host machine where all Mesh-related data will be stored.
  3. 3.
    Replace {version} with the latest version of Mesh.
Notes:
  • Ports 60558 and 60559 are the default ports used for communicating with other peers in the network.
  • In order to disable P2P order discovery and sharing, set USE_BOOTSTRAP_LIST to false.
  • If you are running against a POA testnet (e.g., Kovan), you might want to shorten the BLOCK_POLLING_INTERVAL since blocks are mined more frequently then on mainnet. If you do this, your node will use more Ethereum RPC calls, so you will also need to adjust the ETHEREUM_RPC_MAX_REQUESTS_PER_24_HR_UTC upwards (warning: changing this setting can exceed the limits of your Ethereum RPC provider).
  • If you want to run the mesh in "detached" mode, add the -d switch to the docker run command so that your console doesn't get blocked.

Enabling the GraphQL API

In order to enable the GraphQL API, you just need to add these additional arguments
1
-p 60557:60557 \
2
-e ENABLE_GRAPHQL_SERVER=true \
Copied!
Additionally, to enable the GraphQL playground, just add:
1
-e ENABLE_GRAPHQL_PLAYGROUND=true \
Copied!
Note that the GraphQL API is intended to be private. If you enable the GraphQL API on a production server, we recommend using a firewall or VPC to prevent unauthorized access. See the GraphQL API page for more information.

Persisting State

The Docker container is configured to store all Mesh state (e.g. database files, private key file) in /usr/mesh/0x_mesh. If you want the Mesh state to persist across Docker container re-starts, use the -v flag as included in the command above to mount a local 0x_mesh directory into your container. This is strongly recommended.

Environment Variables

0x Mesh uses environment variables for configuration. Most environment variables are detailed in the Config struct. They are copied here for convenience, although the source code is authoritative.
1
type Config struct {
2
// Verbosity is the logging verbosity: 0=panic, 1=fatal, 2=error, 3=warn, 4=info, 5=debug 6=trace
3
Verbosity int `envvar:"VERBOSITY" default:"2"`
4
// DataDir is the directory to use for persisting all data, including the
5
// database and private key files.
6
DataDir string `envvar:"DATA_DIR" default:"0x_mesh"`
7
// P2PTCPPort is the port on which to listen for new TCP connections from
8
// peers in the network. Set to 60558 by default.
9
P2PTCPPort int `envvar:"P2P_TCP_PORT" default:"60558"`
10
// P2PWebSocketsPort is the port on which to listen for new WebSockets
11
// connections from peers in the network. Set to 60559 by default.
12
P2PWebSocketsPort int `envvar:"P2P_WEBSOCKETS_PORT" default:"60559"`
13
// EthereumRPCURL is the URL of an Etheruem node which supports the JSON RPC
14
// API.
15
EthereumRPCURL string `envvar:"ETHEREUM_RPC_URL" json:"-"`
16
// EthereumChainID is the chain ID specifying which Ethereum chain you wish to
17
// run your Mesh node for
18
EthereumChainID int `envvar:"ETHEREUM_CHAIN_ID"`
19
// UseBootstrapList is whether to bootstrap the DHT by connecting to a
20
// specific set of peers.
21
UseBootstrapList bool `envvar:"USE_BOOTSTRAP_LIST" default:"true"`
22
// BootstrapList is a comma-separated list of multiaddresses to use for
23
// bootstrapping the DHT (e.g.,
24
// "/ip4/3.214.190.67/tcp/60558/ipfs/16Uiu2HAmGx8Z6gdq5T5AQE54GMtqDhDFhizywTy1o28NJbAMMumF").
25
// If empty, the default bootstrap list will be used.
26
BootstrapList string `envvar:"BOOTSTRAP_LIST" default:""`
27
// BlockPollingInterval is the polling interval to wait before checking for a new Ethereum block
28
// that might contain transactions that impact the fillability of orders stored by Mesh. Different
29
// chains have different block producing intervals: POW chains are typically slower (e.g., Mainnet)
30
// and POA chains faster (e.g., Kovan) so one should adjust the polling interval accordingly.
31
BlockPollingInterval time.Duration `envvar:"BLOCK_POLLING_INTERVAL" default:"5s"`
32
// EthereumRPCMaxContentLength is the maximum request Content-Length accepted by the backing Ethereum RPC
33
// endpoint used by Mesh. Geth & Infura both limit a request's content length to 1024 * 512 Bytes. Parity
34
// and Alchemy have much higher limits. When batch validating 0x orders, we will fit as many orders into a
35
// request without crossing the max content length. The default value is appropriate for operators using Geth
36
// or Infura. If using Alchemy or Parity, feel free to double the default max in order to reduce the
37
// number of RPC calls made by Mesh.
38
EthereumRPCMaxContentLength int `envvar:"ETHEREUM_RPC_MAX_CONTENT_LENGTH" default:"524288"`
39
// EnableEthereumRPCRateLimiting determines whether or not Mesh should limit
40
// the number of Ethereum RPC requests it sends. It defaults to true.
41
// Disabling Ethereum RPC rate limiting can reduce latency for receiving order
42
// events in some network conditions, but can also potentially lead to higher
43
// costs or other rate limiting issues outside of Mesh, depending on your
44
// Ethereum RPC provider. If set to false, ethereumRPCMaxRequestsPer24HrUTC
45
// and ethereumRPCMaxRequestsPerSecond will have no effect.
46
EnableEthereumRPCRateLimiting bool `envvar:"ENABLE_ETHEREUM_RPC_RATE_LIMITING" default:"true"`
47
// EthereumRPCMaxRequestsPer24HrUTC caps the number of Ethereum JSON-RPC requests a Mesh node will make
48
// per 24hr UTC time window (time window starts and ends at midnight UTC). It defaults to 200k but
49
// can be increased well beyond this limit depending on your infrastructure or Ethereum RPC provider.
50
EthereumRPCMaxRequestsPer24HrUTC int `envvar:"ETHEREUM_RPC_MAX_REQUESTS_PER_24_HR_UTC" default:"200000"`
51
// EthereumRPCMaxRequestsPerSecond caps the number of Ethereum JSON-RPC requests a Mesh node will make per
52
// second. This limits the concurrency of these requests and prevents the Mesh node from getting rate-limited.
53
// It defaults to the recommended 30 rps for Infura's free tier, and can be increased to 100 rpc for pro users,
54
// and potentially higher on alternative infrastructure.
55
EthereumRPCMaxRequestsPerSecond float64 `envvar:"ETHEREUM_RPC_MAX_REQUESTS_PER_SECOND" default:"30"`
56
// CustomContractAddresses is a JSON-encoded string representing a set of
57
// custom addresses to use for the configured chain ID. The contract
58
// addresses for most common chains/networks are already included by default, so this
59
// is typically only needed for testing on custom chains/networks. The given
60
// addresses are added to the default list of addresses for known chains/networks and
61
// overriding any contract addresses for known chains/networks is not allowed. The
62
// addresses for exchange, devUtils, erc20Proxy, erc721Proxy and erc1155Proxy are required
63
// for each chain/network. For example:
64
//
65
// {
66
// "exchange":"0x48bacb9266a570d521063ef5dd96e61686dbe788",
67
// "devUtils": "0x38ef19fdf8e8415f18c307ed71967e19aac28ba1",
68
// "erc20Proxy": "0x1dc4c1cefef38a777b15aa20260a54e584b16c48",
69
// "erc721Proxy": "0x1d7022f5b17d2f8b695918fb48fa1089c9f85401",
70
// "erc1155Proxy": "0x64517fa2b480ba3678a2a3c0cf08ef7fd4fad36f"
71
// }
72
//
73
CustomContractAddresses string `envvar:"CUSTOM_CONTRACT_ADDRESSES" default:""`
74
// MaxOrdersInStorage is the maximum number of orders that Mesh will keep in
75
// storage. As the number of orders in storage grows, Mesh will begin
76
// enforcing a limit on maximum expiration time for incoming orders and remove
77
// any orders with an expiration time too far in the future.
78
MaxOrdersInStorage int `envvar:"MAX_ORDERS_IN_STORAGE" default:"100000"`
79
// CustomOrderFilter is a stringified JSON Schema which will be used for
80
// validating incoming orders. If provided, Mesh will only receive orders from
81
// other peers in the network with the same filter.
82
//
83
// Here is an example filter which will only allow orders with a specific
84
// makerAssetData:
85
//
86
// {
87
// "properties": {
88
// "makerAssetData": {
89
// "const": "0xf47261b0000000000000000000000000871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c"
90
// }
91
// }
92
// }
93
//
94
// Note that you only need to include the requirements for your specific
95
// application in the filter. The default requirements for a valid order (e.g.
96
// all the required fields) are automatically included. For more information
97
// on JSON Schemas, see https://json-schema.org/
98
CustomOrderFilter string `envvar:"CUSTOM_ORDER_FILTER" default:"{}"`
99
// MaxBytesPerSecond is the maximum number of bytes per second that a peer is
100
// allowed to send before failing the bandwidth check. Defaults to 5 MiB.
101
MaxBytesPerSecond float64 `envvar:"MAX_BYTES_PER_SECOND" default:"5242880"`
102
// AdditionalPublicIPSources is a list of external public IP source like
103
// https://whatismyip.api.0x.org/ which return the IP address in a
104
// text/plain format. This list is prepended to the default sources list.
105
//
106
// It expects a comma delimited list of external sources for example:
107
// ADDITIONAL_PUBLIC_IP_SOURCES="https://ifconfig.me/ip,http://192.168.5.10:1337/ip"
108
AdditionalPublicIPSources string `envvar:"ADDITIONAL_PUBLIC_IP_SOURCES" default:""`
109
}
Copied!
There are some additional environment variable in the main entrypoint for the Mesh executable:
1
type standaloneConfig struct {
2
// EnableGraphQLServer determines whether or not to enable the GraphQL server.
3
// If enabled, GraphQL queries can be sent to GraphQLServerAddr at the /graphql
4
// URL. By default, the GraphQL server is disabled. Please be aware that the GraphQL
5
// API is intended to be a *private* API. If you enable the GraphQL server in
6
// production we recommend using a firewall/VPC or an authenticated proxy to restrict
7
// public access.
8
EnableGraphQLServer bool `envvar:"ENABLE_GRAPHQL_SERVER" default:"false"`
9
// GraphQLServerAddr is the interface and port to use for the GraphQL API.
10
// By default, 0x Mesh will listen on 0.0.0.0 (all available addresses) and
11
// port 60557.
12
GraphQLServerAddr string `envvar:"GRAPHQL_SERVER_ADDR" default:"0.0.0.0:60557"`
13
// EnableGraphQLPlayground determines whether or not to enable GraphiQL, an interactive
14
// GraphQL playground which can be accessed by visiting GraphQLServerAddr in a browser.
15
// See https://github.com/graphql/graphiql for more information. By default, GraphiQL
16
// is disabled.
17
EnableGraphQLPlayground bool `envvar:"ENABLE_GRAPHQL_PLAYGROUND" default:"false"`
18
// EnablePrometheusMoniitoring determines whether or not to enable
19
// prometheus monitoring. The metrics are accessed by scraping
20
// {PrometheusMonitoringServerAddr}/metrics, prometheus is disabled.
21
EnablePrometheusMonitoring bool `envvar:"ENABLE_PROMETHEUS_MONITORING" default:"false"`
22
// PrometheusMonitoringServerAddr is the interface and port to use for
23
// prometheus server metrics endpoint.
24
PrometheusMonitoringServerAddr string `envvar:"PROMETHEUS_SERVER_ADDR" default:"0.0.0.0:8080"`
25
}
Copied!