Skip to content

Commit

Permalink
Add mainnet to config
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Jun 15, 2020
1 parent a33a955 commit c40c93c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
6 changes: 6 additions & 0 deletions js/env-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ export default {
WS_API_ADDR: "wss://api.test.zksync.dev/jsrpc-ws",
HTTP_RPC_API_ADDR: "https://api.test.zksync.dev/jsrpc",
},
"https://zkscan.io": {
API_SERVER: "https://api.zksync.io",
ETH_NETWORK: "mainnet",
WS_API_ADDR: "wss://api.zksync.io/jsrpc-ws",
HTTP_RPC_API_ADDR: "https://api.zksync.io/jsrpc",
},
}[`${location.protocol}//${location.hostname}`];
2 changes: 1 addition & 1 deletion js/zksync.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zksync",
"version": "0.5.10",
"version": "0.5.11",
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
42 changes: 28 additions & 14 deletions js/zksync.js/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
HTTPTransport,
WSTransport
} from "./transport";
import { utils, ethers, Contract } from "ethers";
import {utils, ethers, Contract} from "ethers";
import {
AccountState,
Address,
Expand All @@ -25,42 +25,56 @@ import {
} from "./utils";

export async function getDefaultProvider(
network: "localhost" | "rinkeby" | "ropsten",
network: "localhost" | "rinkeby" | "ropsten" | "mainnet",
transport: "WS" | "HTTP" = "WS"
): Promise<Provider> {
if (network == "localhost") {
if (transport == "WS") {
if (network === "localhost") {
if (transport === "WS") {
return await Provider.newWebsocketProvider("ws://127.0.0.1:3031");
} else if (transport == "HTTP") {
} else if (transport === "HTTP") {
return await Provider.newHttpProvider("http://127.0.0.1:3030");
}
} else if (network == "ropsten") {
if (transport == "WS") {
} else if (network === "ropsten") {
if (transport === "WS") {
return await Provider.newWebsocketProvider(
"wss://ropsten-api.zksync.dev/jsrpc-ws"
);
} else if (transport == "HTTP") {
} else if (transport === "HTTP") {
return await Provider.newHttpProvider(
"https://ropsten-api.zksync.dev/jsrpc"
);
}
} else if (network == "rinkeby") {
if (transport == "WS") {
} else if (network === "rinkeby") {
if (transport === "WS") {
return await Provider.newWebsocketProvider(
"wss://rinkeby-api.zksync.dev/jsrpc-ws"
);
} else if (transport == "HTTP") {
} else if (transport === "HTTP") {
return await Provider.newHttpProvider(
"https://rinkeby-api.zksync.dev/jsrpc"
);
}
} else if (network === "mainnet") {
if (transport === "WS") {
return await Provider.newWebsocketProvider(
"wss://api.zksync.io/jsrpc-ws"
);
} else if (transport === "HTTP") {
return await Provider.newHttpProvider(
"https://api.zksync.io/jsrpc"
);
}
} else {
throw new Error(`Ethereum network ${network} is not supported`);
}
}

export class Provider {
contractAddress: ContractAddress;
public tokenSet: TokenSet;
private constructor(public transport: AbstractJSONRPCTransport) {}

private constructor(public transport: AbstractJSONRPCTransport) {
}

static async newWebsocketProvider(address: string): Promise<Provider> {
const transport = await WSTransport.connect(address);
Expand Down Expand Up @@ -169,9 +183,9 @@ export class Provider {
const notifyDone =
action == "COMMIT"
? transactionStatus.block &&
transactionStatus.block.committed
transactionStatus.block.committed
: transactionStatus.block &&
transactionStatus.block.verified;
transactionStatus.block.verified;
if (notifyDone) {
return transactionStatus;
} else {
Expand Down

0 comments on commit c40c93c

Please sign in to comment.