Build your own Ganache-cli Docker with Ethereum-Bridge

Sachith Harshitha Liyanagama
3 min readJun 13, 2021

So while I was working on a team project as part of my Master's program, we realized since the requirement was to use Ganache as the simulation platform for the Blockchain and so that we could host it on a cloud similar to AWS, we have to use Ganache-CLI. Similarly, it was observed that we have to use an Ethereum-bridge if we are planning to use any on-chain blockchain oracle such as Provable to access data off-chain.

What is a Blockchain Oracle

In order to provide the data immutability and as a built-in functionality, it is not possible to pull in data from or push data out to any external system. Therefore, to fill in the gap between the off-chain data and the internal smart contracts, a certain external service is required. These are named blockchain oracle services. There are few key players in this sector such as Provable(Formerly known as Oraclize) and Chainlink.

Figure 1. Blockchain Oracle Service

The Problem

As a developer, you would use a simulation environment such as Ganache during the development phase of your smart contracts. But in special cases like the usage of Provable there are service fees incurred. This brings the requirement to the simulation environment to be connected to the Ethereum Network. To connect your simulation network to get access to the Provable engine, there is an Ethereum-bridge which is provided by the truffle suite developers. Apparently, this bridge is not part of neither Ganache CLI nor the Ganache UI. You can use the below guide to overcome this issue and also to set up a simulation platform with a built-in bridge.

How to do…

So after a short research, we managed to set up the Ganache-CLI docker image with a built-in Ethereum-Bridge. Both are provided by the Truffle Suite.

So the process is quite simple.

  1. Copy the official source from GIT to a desired path of yours.
git clone https://github.com/trufflesuite/ganache-cli.git

2. Copy this file into the file path “ganache-cli”. The content of the new entry point script is as shown below.

Entry Point Bash File : https://github.com/SachiHarshitha/GanacheCLI-with-EthBridge/blob/main/1entrypoint.sh

#!/bin/bash# Start the Ganache CLI as a background process.
node /app/ganache-core.docker.cli.js &
# Add a small delay to let the Ganache CLI configuration complete.
sleep 10
# Run the Ethereum Bridge on the second account available in the network.
ethereum-bridge -a 1 --dev

3. Edit the Docker File with the below content.

Source : https://github.com/SachiHarshitha/GanacheCLI-with-EthBridge/blob/main/Dockerfile

FROM mhart/alpine-node:14 as builder# Insert nodejs and npm to the original installation.
RUN apk add --no-cache make gcc g++ python git bash nodejs npm
COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
WORKDIR /app
RUN git config --global url.https://github.com/.insteadOf ssh://git@github.com/
RUN npm ci
COPY . .
RUN npx webpack-cli --config ./webpack/webpack.docker.config.js
FROM mhart/alpine-node:14 as runtime
# Install the NPM package for ethereum-bridge.
RUN npm install -g ethereum-bridge
WORKDIR /appCOPY --from=builder "/app/build/ganache-core.docker.cli.js" "./ganache-core.docker.cli.js"
COPY --from=builder "/app/build/ganache-core.docker.cli.js.map" "./ganache-core.docker.cli.js.map"
# Copy the new entry point bash script into the opt/bin path of the image.
COPY 1entrypoint.sh /opt/bin/1entrypoint.sh
ENV DOCKER trueEXPOSE 8545# Set the default entry point to the new bash script.
ENTRYPOINT ["sh","/opt/bin/1entrypoint.sh"]
# Comment Out or Delete the old entry point.
#ENTRYPOINT ["node", "/app/ganache-core.docker.cli.js"]

4. Build the new docker container and run it.

docker build --tag sachi/ganache-cli-withbridge .
docker run --publish 8545:8545 sachi/ganache-cli-withbridge

Special thanks go to, my colleague Ken for the support.

--

--

Sachith Harshitha Liyanagama

My enthusiasm for programming keeps me awake sometimes. But at the end of the day the knowledge I gained never make me regret.