Building Contract Metadata
Zora 1155 and 721 contracts have contract-wide json metadata containing descriptive info about the contract, including a name and image. This json metadata is pinned to IPFS.
The structure of Contract Metadata is defined in a type exported from the SDK, ContractMetadataJson:
type ContractMetadataJson = {
name?: string;
description?: string;
image?: string;
}
The image
field should point to an image file pinned to ipfs.
The Zora Protocol SDK exports a type ContractMetadataJson
that defines this json structure.
Here's some example code for building contract metadata json:
example.ts
import { ContractMetadataJson } from "@zoralabs/protocol-sdk";
import { pinFileWithPinata, pinJsonWithPinata } from "./pinata";
export async function makeContractMetadata({
imageFile,
name,
description,
}: {
imageFile: File;
name: string;
description?: string;
}) {
// upload image to Pinata
const imageFileIpfsUrl = await pinFileWithPinata(imageFile);
// build contract metadata json
const metadataJson: ContractMetadataJson = {
description,
image: imageFileIpfsUrl,
name,
};
// upload token metadata json to Pinata and get ipfs uri
const contractMetadataJsonUri = await pinJsonWithPinata(metadataJson);
return contractMetadataJsonUri;
}