-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.js
More file actions
65 lines (53 loc) · 1.85 KB
/
Copy pathupload.js
File metadata and controls
65 lines (53 loc) · 1.85 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
61
62
63
64
65
import { bundlrStorage, keypairIdentity, Metaplex, toMetaplexFile } from "@metaplex-foundation/js"
import { clusterApiUrl, Connection, Keypair } from "@solana/web3.js"
import base58 from "bs58"
import * as dotenv from "dotenv"
import * as fs from "fs"
dotenv.config()
// update these variables!
// Connection endpoint, switch to a mainnet RPC if using mainnet
const ENDPOINT = clusterApiUrl('devnet')
// Devnet Bundlr address
const BUNDLR_ADDRESS = "https://devnet.bundlr.network"
// Mainnet Bundlr address, uncomment if using mainnet
// const BUNDLR_ADDRESS = "https://node1.bundlr.network"
// NFT metadata
const NFT_NAME = "Golden Ticket"
const NFT_SYMBOL = "GOLD"
const NFT_DESCRIPTION = "A golden ticket that grants access to loyalty rewards"
// Set this relative to the root directory
const NFT_IMAGE_PATH = "nft-upload/pay-logo.svg"
const NFT_FILE_NAME = "pay-logo.svg"
async function main() {
// Get the shop keypair from the environment variable
const shopPrivateKey = process.env.SHOP_PRIVATE_KEY
if (!shopPrivateKey) throw new Error('SHOP_PRIVATE_KEY not found')
const shopKeypair = Keypair.fromSecretKey(base58.decode(shopPrivateKey))
const connection = new Connection(ENDPOINT)
const nfts = Metaplex
.make(connection, { cluster: 'devnet' })
.use(keypairIdentity(shopKeypair))
.use(bundlrStorage({
address: BUNDLR_ADDRESS,
providerUrl: ENDPOINT,
timeout: 60000
}))
.nfts();
const imageBuffer = fs.readFileSync(NFT_IMAGE_PATH)
const file = toMetaplexFile(imageBuffer, NFT_FILE_NAME)
const uploadedMetadata = await nfts.uploadMetadata({
name: NFT_NAME,
symbol: NFT_SYMBOL,
description: NFT_DESCRIPTION,
image: file,
})
console.log(`Uploaded metadata: ${uploadedMetadata.uri}`)
}
main()
.then(() => {
console.log("Done!")
})
.catch((err) => {
console.error(err)
process.exit(1)
})