Encoding Attestation Data

Attestation data is encoded according to the Schema the Attestation is associated with. The Schema is parsed by the client reading the Attestation, in a way that results in a series of data types that can be used to abi.decode the attestation data. In order for this to happen, the Attestation data must first be encoded using abi.encode.

Modelling a Schema as a Solidity Struct

The easiest way to think of a Schema is like a Solidity struct. Let's consider a simple Schema:

(string username, string teamname, uint16 points, bool active)

This can be thought of as a struct:

struct Profile {
    string username;
    string teamname;
    uint16 points;
    bool active;
}

If we were to encode an attestation that references this schema, we could do it client side using the ethers library (or equivalent):

const encodedStruct = ethers.utils.defaultAbiCoder.encode(
  ['string', 'string', 'uint16', 'bool'],
  ['bojo','torries', 3, false]
);

This can later be decoded by some off-chain client, with the subgraph, or by another on-chain contract using Solidity:

Encoding Nested Data

Sometimes a schema is a bit more complicated, in that it contains more than just a flat data structure, and may contain nested data structure like so:

Which can be thought of as this nested struct:

Again, encoding the attestation for this schema using a client side library such as ethers would look like this:

Encoding Arrays

Encoding arrays within attestation data is also straightforward, let's use the example before, but with arrays:

Which can be thought of as this nested struct:

Again, encoding the attestation for this schema using a client side library such as ethers would look like this:

Last updated