-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (44 loc) · 1.95 KB
/
index.js
File metadata and controls
60 lines (44 loc) · 1.95 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
49
50
51
52
53
54
55
56
57
58
59
60
const web3 = require('web3');
const express = require('express');
const Tx = require('ethereumjs-tx');
const config = require('./config');
const app = express();
//Infura HttpProvider Endpoint
web3js = new web3(new web3.providers.HttpProvider("https://ropsten.infura.io/v3/674c8c3bc3c64cc6bd6ce5849f05219c"));
app.get("/test", function (request, response) {
response.send({
test: 150
})
});
app.get('/numVoteTest', async function (req, res) {
var contract = new web3js.eth.Contract(config.lunchContractABI, config.contractAddressLunch);
var returnValue = await contract.methods.numVotes().call({ from: config.contractAddressLunch });
var gasPrice = await web3js.eth.getGasPrice(function (e, r) { console.log('Error: ', e) });
var latestBlock = await web3js.eth.getBlock("latest");
var rawTransaction = {
"from": config.masterAddress,
"gasPrice": gasPrice,
"gasLimit": latestBlock.gasLimit,
"to": config.contractAddressLunch,
"data": contract.methods.numVotes().encodeABI(),
"return value": returnValue
}
res.send({ rawTransaction });
})
app.get('/numVote', async function (req, res) {
//creating contract object
var contract = new web3js.eth.Contract(config.lunchExtendedContractABI, config.contractAddressLunchExtended);
var returnValue = await contract.methods.numVotes().call({ from: config.contractAddressLunchExtended });
var gasPrice = await web3js.eth.getGasPrice(function (e, r) { console.log('Error: ', e) });
var latestBlock = await web3js.eth.getBlock("latest");
var rawTransaction = {
"from": config.masterAddress,
"gasPrice": gasPrice,
"gasLimit": latestBlock.gasLimit,
"to": config.contractAddressLunch,
"data": contract.methods.numVotes().encodeABI(),
"return value": returnValue
}
res.send({ rawTransaction });
});
app.listen(3000, () => console.log('Example app listening on port 3000!'))