-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadNFTs.js
57 lines (49 loc) · 1.38 KB
/
uploadNFTs.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
require("dotenv").config();
const axios = require("axios");
const API_KEY = process.env.OPENSEA_API_KEY;
const CONTRACT_ADDRESS = "0xB0Cbe7f964dd8318981F9C068F060d6De621B20a";
const TOKEN_IDS = [90, 91, 92]; // 你的NFT token ID 列表
const IMAGE_BASE_URL =
"https://raw.githubusercontent.com/chaozhangdev/hinoko/main/img/";
const handleNameFormat = (numberId) => {
return numberId.toString().padStart(4, "0");
};
const uploadNFT = async (tokenId) => {
const metadata = {
name: `Hinoko #${handleNameFormat(tokenId)}`,
description: "",
image: `${IMAGE_BASE_URL}${tokenId}.png`,
};
try {
const response = await axios.post(
"https://api.opensea.io/api/v1/assets",
{
asset_contract_address: CONTRACT_ADDRESS,
token_id: tokenId,
metadata: metadata,
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
},
}
);
if (response.status === 200) {
console.log(`Successfully uploaded NFT #${tokenId}`);
} else {
console.log(`Failed to upload NFT #${tokenId}:`, response.data);
}
} catch (error) {
console.error(
`Error uploading NFT #${tokenId}:`,
error.response ? error.response.data : error.message
);
}
};
const main = async () => {
for (const tokenId of TOKEN_IDS) {
await uploadNFT(tokenId);
}
};
main();