我們這次選擇的鏈為 polygon 使用 (MATIC 代幣)
polygon 測試網為 (Mumbai)
MetaData 與素材檔案將利用 NFT.Storage 存放在 (IPFS) 上
https://wiki.polygon.technology/docs/develop/nftstorage/#creating-your-nft-on-polygon
https://ipfs.io/ipfs/bafkreidynrzkx2rymz257xosvtortuwt5uwcvtergf4lpdbe3f2yudzfia
{
"image": "ipfs://bafkreiet7k6btmxuwwzu7spig4pci45upj2444htkhfjawll43bvmykoaq",
"animation_url": "ipfs://bafkreihsrqpj3sywirldse3k4age6gkfgp2os4cxtkphree32s37u7n5ou?filename=animation.gltf",
"schem": "ipfs://bafkreia4ph2osgfkhpzgqxa6teq7ygifbddf7f4qx3mzmfyujnj7h5utei",
"name": "Creativerse Plot #4900",
"description": "This is plot #4900 located in the Creativerse as (49, 49).",
"attributes": [
{
"display_type": "date",
"value": "1645680146490",
"trait_type": "Last Saved"
},
{
"display_type": "number",
"value": 49,
"trait_type": "Plot X"
},
{
"display_type": "number",
"value": 49,
"trait_type": "Plot Z"
}
]
}
import { NFTStorage, File } from "nft.storage"
import fs from 'fs'
import dotenv from 'dotenv'
dotenv.config()
const { NFT_STORAGE_API_KEY } = process.env
async function storeAsset() {
const client = new NFTStorage({ token: NFT_STORAGE_API_KEY })
const metadata = await client.store({
name: 'ExampleNFT',
description: 'My ExampleNFT is an awesome artwork!',
image: new File(
[await fs.promises.readFile('assets/中藥包0001-0200.gif')],
'preview.gif',
{ type: 'image/gif' }
),
animation_url: new File(
[await fs.promises.readFile('assets/中藥包.gltf')],
'model.gltf',
{ type: 'model/gltf+json' }
),
name: "元宇宙中醫館 中藥包 #4900",
description: "This is 中藥包 #4900 located in the Creativerse as 元宇宙中醫館",
attributes: [
{
"display_type": "date",
"value": "1645680146490",
"trait_type": "Last Saved"
},
{
"display_type": "string",
"value": '元宇宙中醫館',
"trait_type": "中醫館"
},
{
"display_type": "number",
"value": 49,
"trait_type": "中藥包"
}
]
})
console.log("Metadata stored on Filecoin and IPFS with URL:", metadata.url)
}
storeAsset()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});