Initial commit with 🏗️ Scaffold-ETH 2 @ 1.0.5

This commit is contained in:
han
2026-01-10 18:17:37 +07:00
commit 98751c5b87
165 changed files with 29073 additions and 0 deletions

View 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 } });

View 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;
}
}
}

View 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;