-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (40 loc) · 1.48 KB
/
server.js
File metadata and controls
49 lines (40 loc) · 1.48 KB
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
48
const Web3 = require('web3');
const express = require('express');
const cors = require('cors');
const app = express();
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({ extended: true }));
const port = 3000;
const Reputation = require('./build/contracts/Reputation.json');
const web3 = new Web3(new Web3("http://localhost:7545"));
web3.eth.net.isListening()
.then(() => console.log('Connected to Ganache!'))
.catch((err) => console.error(err));
const contractAddress = "0x56f8195D5d8F271D3e9ED045E99A7d734608893D"; // replace with your contract address
const contract = new web3.eth.Contract(Reputation.abi, contractAddress);
// add an authority node to the contract
async function addAuthorityNode(address) {
const accounts = await web3.eth.getAccounts();
console.log(accounts)
return accounts;
//const result = await contract.methods.addAuthorityNode(address).send({ from: accounts[0] });
//return result;
}
// define the endpoint to add an authority node
app.post('/add-authority-node', async (req, res) => {
console.log(req.body)
const address = req.body.address;
try {
const result = await addAuthorityNode(address);
res.status(200).send(result);
} catch (error) {
console.error(error);
res.status(500).send(error);
}
});
// define the endpoint to add an authority node
app.get('/', async (req, res) => {
res.status(200).send('Hiiiii!!!!!!!!');
});
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));