Create Credential Templates
Create Verifiable Credential templates with a single API call
A Verifiable Credential template is equivalent to an NFT collection. Similar to how a NFT collection groups NFTs together, a Verifiable Credential template references the credential type and additional credential configurations that credentials adhere to. Every Verifiable Credential must belong to a template.
When defining a template, the issuer initially specifies a credentials object. Within that the following needs to be provided:
-
type (required): A credential’s private data schema is referred to as “type”. Types act as a protective measure, preventing the addition of unauthorized fields and, as a result, the tampering of the Verifiable Credential. You can define your own.
-
encryption (required): The method chosen to protect the credential’s private data. If set to
none
the credential’s private data will be stored in plain text. To encrypt and protect the credential’s private data, read about the supported encryption modalities. -
storage (required): The location where credentials defined by this template will be stored. Such storage can be on Crossmint, another company’s database, or decentralized storage. Read about the supported storage modalities.
The template issuer must then specify the template’s public metadata:
- metadata (required): A template’s public name, description and imageUrl. Name is required, while the other attributes are optional.
Finally, the issuer provides information on:
-
chain (required): The blockchain where the credential’s contract and associated NFTs will be registered. Currently, only
polygon
andpolygon-amoy
are supported in production and staging, respectively. Interested to launch your verifiable credentials in another blockchain? Get in touch. -
delegatedSignature (optional): A non-custodial wallet of choice to be used for signing credential issuance. By default, the issuer’s Crossmint-managed custodial wallet will be used. Read more about delegated signatures here.
1. Create a Credential Template
To issue a Verifiable Credential you have to first create the template that this credential will adhere to. You can do so via a single API call (requires the API key scope templates.create
):
const myApiKey = "<YOUR_API_KEY>"; // Replace with key from step 2
const templateParams = {
credentials: {
type: "crossmint:5fe6040e-07a1-48bb-97a3-b588a7e927d2:CourseCompletionCertificate",
encryption: "none",
storage: "crossmint",
},
metadata: {
name: "Satoshi University Credentials",
description: "Credentials accredited by Satoshi University",
imageUrl: "https://picsum.photos/400",
},
chain: "polygon-amoy",
};
const options = {
method: "POST",
headers: {
"X-API-KEY": myApiKey,
"Content-Type": "application/json",
},
body: JSON.stringify(templateParams),
};
fetch("https://staging.crossmint.com/api/v1-alpha1/credentials/templates/", options)
.then((response) => response.json())
.then((response) => console.log(JSON.stringify(response)))
.catch((err) => console.error(err));
The template’s metadata will be used by default for the NFT metadata, unless explicitly set when issuing a new credential.
2. Check the status of your template
It takes a few seconds (up to a minute, depending on the blockchain and how congested it is) to deploy a template.
To check the template’s status, you will need the nfts.create
API scope and run the following code.
const templateId = "<YOUR_TEMPLATE_ID>";
const options = { method: "GET", headers: { "X-API-KEY": "<YOUR_API_KEY>" } };
fetch(`https://staging.crossmint.com/api/2022-06-09/actions/${templateId}`, options)
.then((response) => response.json())
.then((response) => console.log(response))
.catch((err) => console.error(err));