Created
November 1, 2021 07:03
-
-
Save rafinskipg/758b8428b616fbfbbba9a2c8582d748a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type NftResponse = { | |
url: string, | |
ipnft: string, | |
ipfsImage: string, | |
hostedImage: string | |
} | |
export async function uploadNFTStorage( | |
path: string, | |
name: string, | |
description: string, | |
keyValues = {} | |
): Promise<NftResponse| null> { | |
try { | |
const client = new NFTStorage({ | |
token: process.env.NFT_STORAGE_KEY as string, | |
}); | |
const file = await fs.promises.readFile(path); | |
const metadata = await client.store({ | |
name: name, | |
description, | |
image: new File([file], `${name}.png`, { type: "image/`png`" }), | |
properties: { | |
custom: keyValues | |
}, | |
}); | |
// console.log(metadata.data) | |
// console.log(metadata.embed()) | |
return { | |
url: metadata.url, | |
ipnft: metadata.ipnft, | |
ipfsImage: metadata.data.image.href, | |
hostedImage: metadata.embed().image.href | |
}; | |
} catch (e) { | |
return null | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment