Sismo Hub Guide: Add a Data Provider to the Sismo Factory
Developer tutorial
Last updated
Developer tutorial
Last updated
This tutorial will explain how to create a in the . Users (through the ) and developers (through the ) will be able to use your Data Provider in order to create .
Group Generators are functions that enable the creation of groups at the center of the Sismo protocol. As groups need to contain data, we need Data Providers to fetch data from external APIs (e.g, Lens, GitHub, Snapshot).
By following this tutorial you will learn how to create a new Data Provider to fetch the data for your desired group.
Data providers are at the foundation of the Sismo Hub architecture. They are designed to abstract the complexity of fetching external APIs for future devs or group creators gathering data. They are meant to be easy to use and reliable for future group generation.
Data Providers enable other group creators to reuse specific data fetching logic, such as calls to APIs.
are composed of Data Source:
Web2 accounts: Twitter, GitHub, Telegram
Web3 accounts: Ethereum addresses, ENS, Lens handle
When creating a group, you need to create a . There are 3 different ways to do so:
Enter a hardcoded list of accounts
Use an already existing
Use a to fetch accounts
Moreover, Data Providers are useful because they enable automatic and frequent group updates, whereas if the group was made of a hardcoded list of accounts it wouldn't be automatic.
For example:
This will fetch all the voters of the CoW Swap proposal number 23 (CIP-23)
This tutorial will show you how to create a Data Provider and make it usable in the Factory.
We will take the example of a Lens Data Provider on top of the Lens API and build our first query that gets the list of collectors of a specific Lens post.
First, you need to clone the Sismo Hub repository
Let's build our Data Provider now 🧑💻
Go to the group-generators/helpers/data-providers
folder and create a new folder:
For our case in this tutorial, we will split our Data Provider into 3 different files:
index.ts
: [mandatory] Contains all the functions you make available to use in a group generator. It will help format data that come from your API queries.
types.ts
: [mandatory] The file where you can define all the types you need.
queries.ts
: Define all your request to the API you want to use.
First, you need to define which query and which types you will use. From what we see in the Lens API docs, the whoCollectedPublication()
query use and return some types, so you need to implement them in your data provider.
First, you can create a query that will use this type in the query.ts
file:
Once done, create the types.ts
file:
Then define all the types you need when using the whoCollectedPublication()
query:
Because Lens API is a GraphQL API, you can use the GraphQL Data Provider already created in the Hub in order to create the query.
As you can see, this query allows fetching 50 users at a time. So you need to create a function that will iterate on this query in order to fetch all the users.
All of this occurs in the index.ts
file:
It is very important to pass an object that contains all your argument as argument of the function that the Factory will use.
Indeed, when the Factory create the group using your data provider, it will use take all the arguments gave by the user as input and create an object from it. Then it will call your function with this object, like this:
That is why the argument of the function used by the Factory must be an object that contains all the possible arguments of your function.
For example in our case we needed to define this type:
Indeed, a Group Generator returns a group that is composed of metadata:
The data
field is where the group of accounts is stored, and its type is a FetchedData
.
And here's an example of how a FetchedData
object looks like:
Finally, you need to reference your newly created Data Provider in the data-provider
folder in order to use it anywhere in the Sismo Hub:
Congrats 🎉 You've just created your first Data Provider!
But now that you have finished, you probably want to test it right?
To do so you need to create an interface-schema.json
file that contains all the information the Factory needs to use your function and display relevant information.
Then you have to reference your schema:
You're almost finished! 😉
As you may have noticed, in the interface-schema.json
there is a countFunctionName.
This is called a count function. Count functions allow the Factory to know how many accounts a request will fetch and thus to know if the data that the user wants to fetch exists.
Let's create it:
This count function (getPublicationCollectorsCount
) will return the number of collectors for a specific Lens post. It allows the Factory to verify if the publicationId
given by the user is correct but also to display the number of accounts the query will fetch on the website.
Finally, you have to reference your count function in the dataProvidersAPIEndpoints
:
By adding this interface file and the count function, you just allowed the factory to:
Fetch information about your newly created Data Provider. It can be now displayed (red box) and used for Factory users when adding eligible accounts.
Call the right count function (regarding the user selection).
If you wish to choose the collectors for a Lens post, you would need to input the post's ID. After clicking the 'Add' button, the Factory will invoke your count function to verify the post's validity and display the number of eligible accounts at the bottom of the screen (see the example above).
You have finally set up your Data Provider for the Factory, congrats! 🎉
For our case, we use the Lens API which doesn't require any access token. However, for many APIs, that's not the case, so if you want to set an access token for the API you want to use, you need to create an environment variable. Here is how to do it:
Then you can add your own access token by adding a new line to this file:
And you need to export the variable in order for you to use it locally on your computer:
You are now able to use it on the Sismo Hub, here is the syntax:
Your Data Provider is now ready, so it's time to push it into prod!
Then you will have to add a new remote to your repo:
You can also create a new branch for your work:
In this tutorial you should have 5 different files changed:
4 files created:
group-generators/helpers/data-providers/tutorial-lens/index.ts
group-generators/helpers/data-providers/tutorial-lens/queries.ts
group-generators/helpers/data-providers/tutorial-lens/types.ts
group-generators/helpers/data-providers/tutorial-lens/interface-schema.json
1 file changed
group-generators/helpers/data-providers/index.ts
Next, add all your changes and push them to your fork:
Don't forget to only add the files related to the Data Provider, and do not add the group you made for testing your Data Provider.
You will then see on your forked repository the following message, you can click on "Compare & pull request" to begin creating your pull request:
When your PR is merged, you'll be able to see your Data Provider implemented in the Sismo Factory
Finally, your Data Provider will be available in the Sismo Hub and anyone will be able to use it to create groups. Great job! 💪
If you want to create a that contains all the voters of your last DAO proposal on Snapshot, simply use the queryProposalVoters
function from the in your by giving the Proposal Identifier as an argument.
If you want to know more on Data Providers, check out this . Alternatively, you can check out the before creating one yourself.
At the end of this tutorial, it will be up to you to do a pull request on the to see your Data Provider integrated and be usable in the (green box) and in the Sismo Hub (red box) 🙌
You can install yarn
.
It is worth noting that the final variable you return at the end of your getWhoCollectedPublication
function is of type FetchedData
. This type is needed if you want to create .
That's why must be the format of the variable you return.
To do this you will have to create a group (only for testing) and import your Data Provider into it, so you can try your request. If you don't know how to create a group, check out the group tutorial .
Okay, so now that your data provider is finished and tested, it can be used by all devs in the Sismo Hub. The next step is making it available to anyone in the . Pretty exciting, isn't it? 🤩
If you want more info on this schema, check this on the Data Provider page.
NB: To be able to use the API key in the Sismo Hub when your badge is deployed, please contact us in #dev-support () after creating your PR so we can add your access token to our infrastructure.
You don't have to store or launch anything on your side. You will just have to add to see your Data Provider live! 😁
First, you will have to the :
You will finally see your branch being compared to the main branch of the repository (blue boxes). You can review your changes and add a meaningful title and comments, and when you are happy with your PR, click "Create Pull request". 😇
For example, here is a valid pull request: (The PR is closed because it's only used as an example for this tutorial)
If your Data Provider requires an API key, contact the team on the in #dev-support in order for us to make your API key usable in the main Sismo Hub and on the Factory.
You will also see it in the Sismo Hub API:
You want to contribute, but you don't have any ideas for Data Providers to create? Check out the current , as you will find some interesting ideas for Data Providers to implement.
If you have any questions or you need help regarding your Data Providers creation process, do not hesitate to join our and ask us in #dev-support or ou . We will be glad to answer you 🤗