-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (42 loc) · 1.29 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
48
49
50
51
52
//write boilder plate code for express with 2 routes post called /mint and /balance
// /mint will take in a wallet address and amount and return a mint signature and transfer signature
// /balance will take in a wallet address and return the balance of the wallet
//
// Path: index.js
//import express
import express from 'express';
import {mint, balance} from "./methods.js";
const app = express();
const port = 3989;
app.use(express.json());
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});
app.post('/mint', async (req, res) => {
const {walletAddress, amount} = req.body;
if(walletAddress === undefined || amount === undefined) {
res.status(400).send({
error: 'invalid request'
});
}
let response = await mint(walletAddress, amount);
if(response.error) {
res.status(500).send(response);
}else {
res.send(response);
}
});
app.post('/balance', async (req, res) => {
const {walletAddress} = req.body;
if (walletAddress === undefined) {
res.status(400).send({
error: 'invalid request'
});
}
let response = await balance(walletAddress);
if(response.error) {
res.status(500).send(response);
}else {
res.send(response);
}
});