UNPKG

@effectai/sdk

Version:

Effect Network Javscript/Typescript SDK (for [https://effect.network](https://effect.network))

33 lines 1.17 kB
import { Base58 } from "@wharfkit/antelope"; export const uploadIpfsResource = async ({ client, data, }) => { try { const { ipfs } = client.network.config; const blob = new Blob([JSON.stringify(data)], { type: "application/json", }); const formData = new FormData(); formData.append("file", blob); if (blob.size > 1024 * 1024 * 10) { throw new Error("File too large, max file size is: 10MB"); } const requestOptions = { method: "POST", body: formData, }; const response = await client.fetchProvider.fetch(`${ipfs.ipfsEndpoint}/api/v0/add?pin=true`, requestOptions); if (!response.ok) { const errorText = await response.text(); throw new Error(`Error in IPFS upload: ${errorText}`); } const json = await response.json(); return json.Hash; } catch (error) { console.error("Error in IPFS upload", error); throw error; } }; export const ipfsCIDToHex = (cid) => { return Base58.decode(cid).hexString; }; //# sourceMappingURL=uploadIpfsResource.js.map