Schemas
Simple Schemas
A schema is a blueprint for an attestation. It describes the various fields an attestation contains and what their data types are. Anyone can create a schema in the registry, and once created, schemas can be re-used by anyone else.
Schemas are stored in the registry as a string value that describes the various fields. For example, to create attestations that describe a person, we can create a schema as follows:
(string username, string teamName, uint16 points, bool active)
This describes a schema with four fields. Any attestation based on this schema can be decoded in Solidity as follows:
(username, teamName, points, active) = abi.decode(
attestationData,
(string, string, uint16, bool)
);
As you can see from this example, a schema is a comma-separated list of tuples, composed of property name and datatype.
Schemas with Nested Data
Many schemas will involve some kind of nested data. To create a schema with nested data, place the nested data in round braces, followed by the property name, for example:
(string username, string teamName, uint16 points, bool active, (string gametype, string gamemode)[] setup)
You can consider this schema as corresponding to the following Solidity structs:
struct Preferences {
string gameType;
string gameMode;
}
struct Profile {
string username;
string teamName;
uint16 points;
bool active;
Preferences[] setup;
}
Schema Metadata
As well as the schema string, schemas have some metadata stored with them:
name
string
(required) The name of schema, stored on-chain
description
string
A link to off-chain description / documentation
context
string
A link to some shared vocabulary / ontology
schema
string
(required) The raw schema string as described above
Schema Contexts / Shared Vocabularies
Schemas have a field called "context", usually a link to some shared vocabulary. This is an important field that gives semantic meaning to the schema, allowing consumers of the attestation to understand exactly what the fields in the schema represent. This removes ambiguity and allows reputation protocols to build powerful semantic graphs when indexing attestations.
For more information on this property and how important it is, see the Linked Data page.
Counterfactual Schemas
Schema IDs are unique to the schema content, and are created from the keccak hash of the schema string. This means that schemas can be created counter-factually, allowing for things like circular relationships between schemas.
Experimental Features for Advanced Schemas
These features are advanced and experimental schema features that allow you to create schemas with sophisticated properties. Feel free to get in contact if you have any questions.
NOTE: caution should be taken with these features as they are experimental and likely to change, and may not be supported by all indexers!
Last updated