Files
sre-01-tokenization/packages/nextjs/utils/tokenization/ipfs-fetch.ts
2026-01-10 18:17:37 +07:00

17 lines
598 B
TypeScript

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