Initial commit with 🏗️ Scaffold-ETH 2 @ 1.0.5
This commit is contained in:
16
packages/nextjs/utils/tokenization/ipfs-fetch.ts
Normal file
16
packages/nextjs/utils/tokenization/ipfs-fetch.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
const fetchFromApi = ({ path, method, body }: { path: string; method: string; body?: object }) => {
|
||||
return fetch(path, {
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.catch(error => console.error("Error:", error));
|
||||
};
|
||||
|
||||
export const addToIPFS = (yourJSON: object) => fetchFromApi({ path: "/api/ipfs/add", method: "Post", body: yourJSON });
|
||||
|
||||
export const getMetadataFromIPFS = (ipfsHash: string) =>
|
||||
fetchFromApi({ path: "/api/ipfs/get-metadata", method: "Post", body: { ipfsHash } });
|
||||
35
packages/nextjs/utils/tokenization/ipfs.ts
Normal file
35
packages/nextjs/utils/tokenization/ipfs.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { create } from "kubo-rpc-client";
|
||||
|
||||
const PROJECT_ID = "2GajDLTC6y04qsYsoDRq9nGmWwK";
|
||||
const PROJECT_SECRET = "48c62c6b3f82d2ecfa2cbe4c90f97037";
|
||||
const PROJECT_ID_SECRECT = `${PROJECT_ID}:${PROJECT_SECRET}`;
|
||||
|
||||
export const ipfsClient = create({
|
||||
host: "ipfs.infura.io",
|
||||
port: 5001,
|
||||
protocol: "https",
|
||||
headers: {
|
||||
Authorization: `Basic ${Buffer.from(PROJECT_ID_SECRECT).toString("base64")}`,
|
||||
},
|
||||
});
|
||||
|
||||
export async function getNFTMetadataFromIPFS(ipfsHash: string) {
|
||||
for await (const file of ipfsClient.get(ipfsHash)) {
|
||||
// The file is of type unit8array so we need to convert it to string
|
||||
const content = new TextDecoder().decode(file);
|
||||
// Remove any leading/trailing whitespace
|
||||
const trimmedContent = content.trim();
|
||||
// Find the start and end index of the JSON object
|
||||
const startIndex = trimmedContent.indexOf("{");
|
||||
const endIndex = trimmedContent.lastIndexOf("}") + 1;
|
||||
// Extract the JSON object string
|
||||
const jsonObjectString = trimmedContent.slice(startIndex, endIndex);
|
||||
try {
|
||||
const jsonObject = JSON.parse(jsonObjectString);
|
||||
return jsonObject;
|
||||
} catch (error) {
|
||||
console.log("Error parsing JSON:", error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
126
packages/nextjs/utils/tokenization/nftsMetadata.ts
Normal file
126
packages/nextjs/utils/tokenization/nftsMetadata.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
const nftsMetadata = [
|
||||
{
|
||||
description: "It's actually a bison?",
|
||||
external_url: "https://austingriffith.com/portfolio/paintings/", // <-- this can link to a page for the specific file too
|
||||
image: "https://austingriffith.com/images/paintings/buffalo.jpg",
|
||||
name: "Buffalo",
|
||||
attributes: [
|
||||
{
|
||||
trait_type: "BackgroundColor",
|
||||
value: "green",
|
||||
},
|
||||
{
|
||||
trait_type: "Eyes",
|
||||
value: "googly",
|
||||
},
|
||||
{
|
||||
trait_type: "Stamina",
|
||||
value: 42,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "What is it so worried about?",
|
||||
external_url: "https://austingriffith.com/portfolio/paintings/", // <-- this can link to a page for the specific file too
|
||||
image: "https://austingriffith.com/images/paintings/zebra.jpg",
|
||||
name: "Zebra",
|
||||
attributes: [
|
||||
{
|
||||
trait_type: "BackgroundColor",
|
||||
value: "blue",
|
||||
},
|
||||
{
|
||||
trait_type: "Eyes",
|
||||
value: "googly",
|
||||
},
|
||||
{
|
||||
trait_type: "Stamina",
|
||||
value: 38,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "What a horn!",
|
||||
external_url: "https://austingriffith.com/portfolio/paintings/", // <-- this can link to a page for the specific file too
|
||||
image: "https://austingriffith.com/images/paintings/rhino.jpg",
|
||||
name: "Rhino",
|
||||
attributes: [
|
||||
{
|
||||
trait_type: "BackgroundColor",
|
||||
value: "pink",
|
||||
},
|
||||
{
|
||||
trait_type: "Eyes",
|
||||
value: "googly",
|
||||
},
|
||||
{
|
||||
trait_type: "Stamina",
|
||||
value: 22,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "Is that an underbyte?",
|
||||
external_url: "https://austingriffith.com/portfolio/paintings/", // <-- this can link to a page for the specific file too
|
||||
image: "https://austingriffith.com/images/paintings/fish.jpg",
|
||||
name: "Fish",
|
||||
attributes: [
|
||||
{
|
||||
trait_type: "BackgroundColor",
|
||||
value: "blue",
|
||||
},
|
||||
{
|
||||
trait_type: "Eyes",
|
||||
value: "googly",
|
||||
},
|
||||
{
|
||||
trait_type: "Stamina",
|
||||
value: 15,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "So delicate.",
|
||||
external_url: "https://austingriffith.com/portfolio/paintings/", // <-- this can link to a page for the specific file too
|
||||
image: "https://austingriffith.com/images/paintings/flamingo.jpg",
|
||||
name: "Flamingo",
|
||||
attributes: [
|
||||
{
|
||||
trait_type: "BackgroundColor",
|
||||
value: "black",
|
||||
},
|
||||
{
|
||||
trait_type: "Eyes",
|
||||
value: "googly",
|
||||
},
|
||||
{
|
||||
trait_type: "Stamina",
|
||||
value: 6,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: "Raaaar!",
|
||||
external_url: "https://austingriffith.com/portfolio/paintings/", // <-- this can link to a page for the specific file too
|
||||
image: "https://austingriffith.com/images/paintings/godzilla.jpg",
|
||||
name: "Godzilla",
|
||||
attributes: [
|
||||
{
|
||||
trait_type: "BackgroundColor",
|
||||
value: "orange",
|
||||
},
|
||||
{
|
||||
trait_type: "Eyes",
|
||||
value: "googly",
|
||||
},
|
||||
{
|
||||
trait_type: "Stamina",
|
||||
value: 99,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export type NFTMetaData = (typeof nftsMetadata)[number];
|
||||
|
||||
export default nftsMetadata;
|
||||
Reference in New Issue
Block a user