Usage
Once initialized, the HatsDetailsClient can be used for reading and storing data from/to IPFS, in a predetermined format.
Store
Use the the following function in order to store/pin data to IPFS.
The data is expected to be compatible with the provided schema, otherwise an error will be thrown. If data was successfully pinned, its CID (content identifier). This can then be used for reading the data back from IPFS.
const cid = await hatsDetailsClient.pin({
type: "1.0",
data: {
name: "Hat",
description: "This is a hat",
},
});Read
Read data from IPFS.
const data = await hatsDetailsClientDefaultSchema.get(
"QmcSopxmw5rMEEEU8NmGGQ2mbHJ293CGEiQ4r4w4jEECVy"
);The returned data has the following type:
{
parsedData: z.infer<T> | null;
rawData: unknown | null;
error: { message: string } | null;
}If data was successfully fetched and is compatible with the client's schema, then the parsed data will be in the
parsedDatafield, while therawDataanderrorfields will benull.If data was successfully fetched but is not compatible with the client's schema, then the data will be in the
rawDatafield, while thedataanderrorfields will benull.If an error occurred, then the
dataandrawDatafields will benull, and theerrorfield will contain an object with amessagefield.
Last updated