-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmintnft.js
48 lines (41 loc) · 1.18 KB
/
mintnft.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
const fs = require('fs');
const FormData = require('form-data');
const download = require('image-downloader')
require('dotenv').config();
// /api/mintnft
export default async function handler(req, res) {
try{
const url = req.body.imageUrl;
const title = req.body.title;
const message = req.body.message;
const type = req.body.type;
const address = req.body.address;
const { filename } = await download.image({
url: url,
dest: './serverImage'
})
console.log(filename);
const form = new FormData();
const fileStream = fs.createReadStream('./' + filename);
form.append('file', fileStream);
const options = {
method: 'POST',
body: form,
headers: {
"Authorization": process.env.NFTPORT_APIKEY,
},
};
const tx = await fetch("https://api.nftport.xyz/easy_mint?" + new URLSearchParams({
chain: type,
name: title,
description: message,
mint_to_address: address,
}), options)
const txData = await tx.json();
console.log(txData);
return res.status(200).json({ msg: txData });
} catch(error) {
console.error(error);
return res.status(500).json({ error });
}
}