-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
101 lines (89 loc) · 2.57 KB
/
server.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import express from 'express';
import bodyParser from 'body-parser'
import BnbManager from "./src/centerpirme.js";
import cors from 'cors';
var bnbManager = new BnbManager("https://data-seed-prebsc-1-s1.binance.org:8545");
const app = express(),
port = 3080;
// place holder for the data
const users = [];
app.use(cors())
app.use(bodyParser.json());
app.post('/api/createWallet', (req, res) => {
const password = req.body.password;
let wallet = bnbManager.createAccount(password)
console.log(wallet);
res.json(wallet);
});
app.post('/api/importWallet', (req, res) => {
try {
const password = req.body.password;
const keystore = req.body.keystore;
let wallet = bnbManager.importWalletByKeystore(keystore,password)
console.log(wallet);
res.json(wallet);
} catch(e) {
return res.status(401).send({
message : e.message
});
}
});
app.post('/api/bnbBalance', async function(req,res) {
try {
const address = req.body.address;
let balance = await bnbManager.getBnbBalance(address)
console.log(balance);
res.json(balance);
} catch(e) {
return res.status(401).send({
message : e.message
});
}
});
app.post('/api/tokenBalance', async function(req,res) {
try {
const address = req.body.address;
const tokenContractAddress = req.body.tokenAddress;
let balance = await bnbManager.getBEPTokenBalance(tokenContractAddress,address)
console.log(balance);
res.json(balance);
} catch(e) {
return res.status(401).send({
message : e.message
});
}
});
app.post('/api/sendBnb', async function(req,res) {
try {
const keystore = req.body.keystore;
const password = req.body.password;
const toAddress = req.body.toAddress;
const amount = req.body.amount;
let balance = await bnbManager.sendBNB(keystore,password,toAddress,amount,3)
console.log(balance);
res.json(balance);
} catch(e) {
return res.status(401).send({
message : e.message
});
}
});
app.post('/api/sendToken', async function(req,res) {
try {
const keystore = req.body.keystore;
const password = req.body.password;
const tokenContractAddress = req.body.tokenContractAddress;
const toAddress = req.body.toAddress;
const amount = req.body.amount;
let balance = await bnbManager.sendToken(keystore,password,tokenContractAddress,toAddress,parseFloat(amount),3)
console.log(balance);
res.json(balance);
} catch(e) {
return res.status(401).send({
message : e.message
});
}
});
app.listen(port, () => {
console.log(`Server listening on the port::${port}`);
});