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
.
The SDK offers a much easier to encode a JSON object into attestation data. However, this information outlines the low-level steps required to encode attestation data.
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:
If we were to encode an attestation that references this schema, we could do it client side using the ethers library (or equivalent):
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