Schema Creation
Creating a schema for a basic notary system.
Understanding What We Need
The first step to creating a successful schema is understanding exactly what data your application needs. Let's say, for our application, we want to store two things:
contractDetails: a string of text, corresponding to what Bob is signing
signer: an address, corresponding to Bob's account
Note that the attester's address is automatically recorded in any attestation, so we do not need to store this in our schema.
Creating the Schema
Now that we know what we want to store, we will create a schema on Sign Protocol. We can accomplish this in two ways: first, we can use the Schema Builder. This is perfect for non-coders or setting up a schema quickly, rather than performing the action through code. Second, we can create it by directly interfacing with Sign Protocol's Smart Contract or using the NPM SDK.
The first step is to name your schema, add a description, and choose where to store attestation data. In this tutorial, we will store data on-chain using the Base Sepolia Testnet. Once you choose your configuration, continue to the next step.
NOTE: If you select a data storage option that is not directly on-chain (such as Arweave/IPFS), your schema will require Hybrid Attestations. Our SDK will handle this for you, but if you are interacting directly with Sign Protocol smart contracts, ensure that you are passing in an encoded Content ID (CID) as data
when creating a hybrid attestation.
Schema Builder
![](https://docs.sign.global/~gitbook/image?url=https%3A%2F%2F3152654701-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fw182g9YzR34mTxEBTKXX%252Fuploads%252FoikGmNqxFUPWFDDpIGut%252Fimage.png%3Falt%3Dmedia%26token%3D0a7feb51-bc64-4afd-bd90-1ef8a58f9141&width=768&dpr=4&quality=100&sign=db38fd25&sv=1)
The next step is to create the schema's data structure. As stated earlier, we will create two fields: contractDetails
and signer
. The Schema Builder allows you to enter fields in a user-friendly UI or manually edit the JSON data structure (click "Input Raw Data"). Once you have entered your schema data structure fields, continue to the next step.
![](https://docs.sign.global/~gitbook/image?url=https%3A%2F%2F3152654701-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fw182g9YzR34mTxEBTKXX%252Fuploads%252Fkzyl2HukKVRkCwv1xgxj%252Fimage.png%3Falt%3Dmedia%26token%3D3bb87425-d4f0-4ebb-bdf3-90446b916178&width=768&dpr=4&quality=100&sign=71503b73&sv=1)
When creating a schema, you can designate an additional smart contract address that will be called whenever an event occurs (attestation created, revoked, etc). This can be useful for taking payments or reverting transactions (when some verification fails, i.e. whitelist), but it is outside the scope of this tutorial, so we will leave the field blank for now. We will leave the attestation as non-revocable: Alice cannot make mistakes. Once you have completed this step, press "Create Schema".
![](https://docs.sign.global/~gitbook/image?url=https%3A%2F%2F3152654701-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fw182g9YzR34mTxEBTKXX%252Fuploads%252FCrBnUoOVi7t5fLrOF5Yn%252Fimage.png%3Falt%3Dmedia%26token%3D218a79fe-7fc8-499e-8ee7-7c08db5730af&width=768&dpr=4&quality=100&sign=f3d0ecde&sv=1)
Success! You have successfully created your schema. Click "View Schema" to go to your schema's page.
![](https://docs.sign.global/~gitbook/image?url=https%3A%2F%2F3152654701-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fw182g9YzR34mTxEBTKXX%252Fuploads%252FcxrZc045SiEKZZqfFSyn%252Fimage.png%3Falt%3Dmedia%26token%3D70189187-f89a-43ec-a449-1f84698a6300&width=768&dpr=4&quality=100&sign=efc56881&sv=1)
NPM SDK
Install the SDK into your project. Create a SignProtocolClient to make calls that write to the blockchain. The private key field is optional if you are operating from the frontend as the SDK will attempt to use window.ethereum
if no private key is provided for signing transactions. If you use the SDK from a Node backend, you must provide a private key to make write calls to the blockchain.
NOTE: The account
variable is marked as optional. If it is not provided, the SDK will use the provider from window.ethereum
by default to derive an account. If a provider from window.ethereum
cannot be located when an account is not provided, calls to the SDK will fail.
Next, you will need to create the schema we described above.
This will return information from the transaction, including the schema ID and transaction hash. For example, res
may look like the following:
Now that you have created your schema, continue to the next page to create an attestation using this schema.
Last updated