Blueprint Management (CIP-57)
Guide to managing smart contract blueprints with the Anvil API - creating, finding, and deleting blueprints.
Last updated
Was this helpful?
Was this helpful?
// Import your blueprint (typically from an Aiken build)
import plutusJson from "../hello-world/plutus.json" with { type: "json" };
// Setup API key and content type
const headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
};
// Define the API endpoint
const blueprintsUrl = "https://preprod.api.ada-anvil.app/v2/services/blueprints";async function upsertBlueprint() {
try {
// Prepare the request body with your CIP-57 blueprint
const input = { blueprint: plutusJson };
const res = await fetch(blueprintsUrl, {
method: "POST",
body: JSON.stringify(input),
headers,
});
const json = await res.json();
// The response contains:
// - jsonSchema: Generated JSON schema from the blueprint
// - scriptAddresses: Record of validator hashes and their addresses
// - blueprintId: ID of the created/updated blueprint
console.log("json", JSON.stringify(json, null, 2));
} catch (error) {
console.log("error", error);
}
}async function findBlueprints() {
try {
const url = new URL(blueprintsUrl);
// Optional search parameters
url.searchParams.set("title", "cardano-forge/vesting-contract"); // Filter by title
url.searchParams.set("version", "0.0.0"); // Filter by version
// Additional optional parameters: limit, offset, sortBy, order
const res = await fetch(url, {
method: "GET",
headers,
});
const json = await res.json();
// The response contains:
// - results: Array of matching blueprints
// - total: Total count of matching blueprints
console.log("json", JSON.stringify(json, null, 2));
} catch (error) {
console.log("error", error);
}
}async function deleteBlueprint() {
try {
const url = new URL(blueprintsUrl);
// Required parameter
url.searchParams.set("title", "cardano-forge/vesting-contract");
// Optional parameter - if omitted, all versions with the specified title will be deleted
url.searchParams.set("version", "0.0.0");
const res = await fetch(url, {
method: "DELETE",
headers,
});
const json = await res.json();
// The response contains:
// - deleted: Array of strings identifying the deleted blueprints
console.log("json", JSON.stringify(json, null, 2));
} catch (error) {
console.log("error", error);
}
}