Deploying 0x on the Matic testnet

  • Deploying 0x contracts on Matic testnet
  • Starting an exchange on Matic testnet using 0x-launch-kit

Pre-requisite

You need system-wide installations of

  • Python 3
  • Node.js 8+
  • Yarn 1.9.4+

Deploy contracts

Clone the 0x-monorepo and install node dependencies

$ git clone https://github.com/0xProject/0x-monorepo.git
$ cd 0x-monorepo/
$ yarn install
  • Open packages/migrations/src/migration.ts file
  • Find the line
    const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync();
  • Replace it with
    const accounts: string[] = ['0x56F65dCD821c660b4f3E833696747F5D8e3C537B', '0x685A01B16909eC890B548D9DFf6E7ABF4ec0A24e'];
  • Feel free to change these two addresses with yours, they will be use as owners of AssetProxyOwnerContract.
$ PKG=@0x/migrations yarn build
$ packages/migrations/bin/0x-migrate.js --rpc-url 'https://testnet2.matic.network' --from $DeployAddress --pk $PrivatekeyForDeployAddress
...
export enum NetworkId {
Mainnet = 1,
Ropsten = 3,
Rinkeby = 4,
Kovan = 42,
Ganache = 50,
Matic = 8995,
}
...
const networkToAddresses: { [networkId: number]: ContractAddresses } = {
...
8995: {
exchange: '0xd30d3d36daa6da31d481c19eaccd94558c1aa594',
erc20Proxy: '0x0a53e142138c0d68f5cf968cc74c6f633df57f6b',
erc721Proxy: '0x8fb632da59e73450e097847c0c75608f79770182',
erc1155Proxy: '0xcc270ac66fdde50ea78c6e6a4a334739a2e3f59d',
forwarder: '0x51eb0db2c4a7bcfe18f83f3bdbfaec604056cb03',
orderValidator: '0x0a999c924736b8ec96f01fc959365ebd999a8dab',
zrxToken: '0xb1b57aca0977fdc772bda3ee292b189f363bcea0',
etherToken: '0xbf4263c8842b48c2f7cb1ceb237ae0207952edab',
assetProxyOwner: '0x1f02042d523d9d8b5eafe6eb6d2945b1cf14dd2d',
dutchAuction: '0xc06123a6a87f9866cd74952d3436a78a37a3a46b',
coordinatorRegistry: '0x9ab4d2039e07d08178fac0964cf967f3bd2e25e7',
coordinator: '0xa100ac285e42e62b8d802428d715963f18932aab',
multiAssetProxy: '0x3cf1c836071578a1e900236abf9d2ef0c966c53a',
staticCallProxy: '0x66dafa927c0b36954b67508ad2ee065ac1715024',
devUtils: '0x944131374d60fbdc8d99a05cfd42bb23d33142d9',
},
};
...
$ PKG=@0x/contract-addresses yarn build

0x-launch-kit-backend

Clone the 0x-launch-kit-backend in the same parent directory with 0x-monorepo. Don’t install the dependencies yet!

$ git clone https://github.com/0xProject/0x-launch-kit-backend.git
$ cd 0x-launch-kit-backend/
  • Find all line
    "@0x/contract-addresses" "^3.0.1"
  • Replace with
    "@0x/contract-addresses" "file:../0x-monorepo/packages/contract-addresses"
$ yarn install --frozen-lockfile
  • Delete the js directory
  • Delete all scripts from package.json that end with :js
[
'0xb1b57aca0977fdc772bda3ee292b189f363bcea0', // ZRX on Matic
'0xbf4263c8842b48c2f7cb1ceb237ae0207952edab', // WETH on Matic
]
NETWORK_ID=8995
RPC_URL=https://testnet2.matic.network
$ yarn build:ts
$ yarn start:ts
$ curl http://localhost:3000/v2/orders
{"total":0,"page":1,"perPage":20,"records":[]}

0x-launch-kit-frontend

Clone the 0x-launch-kit-frontend in the same parent directory with 0x-monorepo and 0x-launch-kit-backend.

$ git clone https://github.com/0xProject/0x-launch-kit-frontend.git
$ cd 0x-launch-kit-frontend/
$ yarn install --frozen-lockfile
export const DEFAULT_GAS_PRICE = new BigNumber(0);
export enum Network {
Mainnet = 1,
Rinkeby = 4,
Kovan = 42,
Ganache = 50,
Matic = 8995,
}
{
"general": {
"title": "Launch Kit"
},
"tokens": [
{
"symbol": "zrx",
"name": "0x Protocol Token",
"primaryColor": "#333333",
"icon": "assets/icons/zrx.svg",
"addresses": {
"8995": "0xb1b57aca0977fdc772bda3ee292b189f363bcea0"
},
"decimals": 18,
"displayDecimals": 2
},
{
"symbol": "weth",
"name": "Wrapped Ether",
"primaryColor": "#3333ff",
"icon": "assets/icons/weth.svg",
"addresses": {
"8995": "0xbf4263c8842b48c2f7cb1ceb237ae0207952edab"
},
"decimals": 18,
"displayDecimals": 2
}
],
"pairs": [
{
"base": "zrx",
"quote": "weth"
}
],
"marketFilters": [
{
"text": "ETH",
"value": "weth"
}
]
}
$ REACT_APP_NETWORK_ID= '8995' REACT_APP_RELAYER_URL= 'http://localhost:3000/v2' yarn start
Metamask not installed
Wrong network

Appendix: Deploy 0x version 1

To deploy version 1 contracts, checkout the v1-protocol branch of 0x-monorepo

$ cd 0x-monorepo/
$ git checkout v1-protocol
$ yarn install
$ yarn add truffle-hdwallet-provider
#!/usr/bin/env node
import { logUtils } from '@0xproject/utils';
import HDWalletProvider = require('truffle-hdwallet-provider');
import { runMigrationsAsync } from './migration';(async () => {
const sender = '0x913dA4198E6bE1D5f5E4a40D0667f70C0B5430Eb';
const senderPk = 'fae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a';
const provider = new HDWalletProvider(senderPk, 'https://testnet2.matic.network');
const txDefaults = { from: sender.toLowerCase() };
const artifactsDir = 'artifacts/1.0.0';
await runMigrationsAsync(provider, artifactsDir, txDefaults);
process.exit(0);
})().catch(err => {
logUtils.log(err);
process.exit(1);
});
  • Find the line
    const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync();
  • Replace it with
    const accounts: string[] = ['0x913dA4198E6bE1D5f5E4a40D0667f70C0B5430Eb', '0x685A01B16909eC890B548D9DFf6E7ABF4ec0A24e'];
  • Feel free to change these two addresses with yours, make sure the first address is your sender above.
$ PKG=@0xproject/migrations yarn build
$ cd packages/migrations/
$ yarn migrate

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store