Skip to content

Instantly share code, notes, and snippets.

View schadokar's full-sized avatar
😵

Shubham Chadokar schadokar

😵
View GitHub Profile
@schadokar
schadokar / Dockerfile.ganache
Created April 11, 2019 08:15
Dockerfile for the ganache-cli image
# base image - node:alpine
FROM node:alpine
# set the working directory to /app
WORKDIR /app
# install ganache-cli globally
RUN npm install -g ganache-cli
# set the command ganache-cli -h 0.0.0.0
@schadokar
schadokar / Message.sol
Created April 11, 2019 08:17
Message Smart Contract
pragma solidity ^0.4.25;
contract Message {
string public message;
constructor(string memory _message) public {
message = _message;
}
@schadokar
schadokar / compile.js
Last active April 11, 2019 09:16
Compile the smart contract
const fs = require("fs-extra");
const path = require("path");
const solc = require("solc");
const compile = () => {
try {
// build path where compiled contract will save
const buildPath = path.resolve(__dirname,"./build");
// remove the build folder if it exist
@schadokar
schadokar / deploy.js
Created April 11, 2019 13:33
Deploy the smart contract to the ethereum network
const fs = require("fs-extra");
const path = require("path");
const {web3, web3Network} = require("./web3");
const compiledContract = require("./build/Message.json");
const circularJSON = require('circular-json');
const deploy = async (mymessage) => {
try {
// set the receipt path
const receiptPath = path.resolve("ethereum","receipt-"+web3Network+".json");
@schadokar
schadokar / web3.js
Created April 11, 2019 13:49
web3 provider
// web3.js
const fs = require("fs");
const Web3 = require("web3");
const web3Network = "ganache"
// creating a web3 instance on ganache-cli network
// Here the url is http://ganache:8545
// this ganache is the name of the container in which ganache-cli is running
const web3 = new Web3(new Web3.providers.HttpProvider("http://ganache:8545"))
@schadokar
schadokar / logic.js
Created April 11, 2019 16:45
Interact with deployed smart contract
const fs = require("fs-extra");
const {web3} = require("./web3");
const compileContract = require("./build/Message.json");
// Contract object deployed on network (ganache-cli or testnet or mainnet)
// network can be selected in web3 file
// cont
const getContractObject = () => {
@schadokar
schadokar / package.json
Created April 13, 2019 13:45
docker-ethereum-dapp package.json
{
"name": "docker-ethereum",
"version": "1.0.0",
"description": "",
"main": "./server/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon ./server/index.js"
},
"author": "",
@schadokar
schadokar / contract-API.js
Created April 13, 2019 15:00
docker-ethereum contract-API it will call deploy and compile function of ethereum
const express = require("express");
const router = express.Router();
const compile = require("../../ethereum/compile");
const deploy = require("../../ethereum/deploy");
// Compile the contract
router.post("/compile", async function(req, res, next) {
const result = compile();
res.send(result);
});
@schadokar
schadokar / smart-contract-API.js
Created April 13, 2019 15:18
docker-ethereum call the logic.js
const express = require("express");
const router = express.Router();
const logic = require("../../ethereum/logic");
router.get("/", async (req,res,next) => {
let message = await logic.getMessage();
res.send(message);
})
@schadokar
schadokar / index.js
Created April 13, 2019 15:27
docker-ethereum server of the dapp
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const app = express();
const contractAPIRoutes = require("./routes/contract-API");
const smartContractAPIRoutes = require("./routes/smart-contract-API");
const port = 4000;