-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (40 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
*
* This file doesn't updates the contract
* It was the initial backend setup for the backend that might interact directly with the Solidity deployed
* contract and perform sensitive tasks on the backend
*/
const express = require("express");
const server = express();
const cors = require("cors");
const Web3 = require("web3");
const contract = require("@truffle/contract");
const artifacts = require("./build/contracts/flipCard.json");
const CONTACT_ABI = require("./config");
const CONTACT_ADDRESS = require("./config");
const routes = require("./routes");
server.use(cors());
server.use(express.json());
server.use(express.urlencoded({ extended: false }));
const PORT = process.env.PORT || 8000;
if (typeof web3 !== "undefined") {
var web3 = new Web3(web3.currentProvider);
} else {
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
}
server.listen(PORT, async () => {
const accounts = await web3.eth.getAccounts();
const flipCard = new web3.eth.Contract(
CONTACT_ABI.CONTACT_ABI,
CONTACT_ADDRESS.CONTACT_ADDRESS
);
// const LMS = contract(CONTACT_ABI.CONTACT_ABI)
// LMS.setProvider(web3.currentProvider);
// console.log(LMS)
// const lms = await LMS.deployed();
server.set("accounts", accounts);
server.set("flipcard", flipCard);
console.log(accounts)
routes(server,accounts,flipCard)
});
exports.server = server;