Skip to content

Commit

Permalink
Added chain id as environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Sep 18, 2023
1 parent fcfbf01 commit 8879add
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ COPY --from=builder "/build/" "/app/"

WORKDIR /app/gnt2-docker-yagna
ENV NODE_ENV=production
EXPOSE 8545
CMD ["yarn", "start"]
16 changes: 14 additions & 2 deletions gnt2-docker-yagna/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ const PORT = 8545;
import { factories } from "gnt2-contracts";
import {ethers} from "ethers";
async function start() {
const provider = await startGanache(PORT);
let chainId: number | undefined = undefined;
if (!process.env.GANACHE_CHAIN_ID) {
throw new Error("GANACHE_CHAIN_ID env variable not set or empty");
}
chainId = parseInt(process.env.GANACHE_CHAIN_ID);
if (!chainId) {
throw new Error("GANACHE_CHAIN_ID should be a number greater than 0");
}

const provider = await startGanache(PORT, chainId);
console.log("Ganache started. Chain id: " + (await provider.getNetwork()).chainId);

//Create wallets by taking defaults from ethereum_waffle and setting ganache as provider
Expand All @@ -16,7 +25,10 @@ async function start() {
}
const deployWallet = wallets[0];
const deployer = deployWallet.address;
const chainId = (await provider.getNetwork()).chainId;
const chainIdFromNetwork = (await provider.getNetwork()).chainId;
if ( chainId != chainIdFromNetwork ) {
throw new Error(`Chain ID mismatch ${chainId} vs ${chainIdFromNetwork}`);
}
console.log(`Chain ID: ${chainId}`);

console.log("Deploying NGNT faucet...");
Expand Down
4 changes: 2 additions & 2 deletions gnt2-docker-yagna/startGanache.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function printWallets(wallets) {
console.log("");
}

async function startGanache(port) {
async function startGanache(port, chainId) {
const options = {
accounts: defaultAccounts,
hardfork: "london",
chainId: 4
chainId: chainId
};
const server = Ganache.server(options);

Expand Down

0 comments on commit 8879add

Please sign in to comment.