Set Subscribe Middleware
Workflow
Set middleware for subscribe is a powerful API that allows developers to customize their apps and create a unique experience for their users. The API interacts with the smart contract and sets the defined rules on how it should behave for a specific action, such as subscribing to a profile.
First, data should be presented to the user in a readable format when signing from the wallet. To do that you’ll need to call the
createSetSubscribeDataTypedData
API that takes care of this.If you’re unfamiliar with typed data, you can read more about it here.
This API sets the parameters for subscribing such as
tokenURI
andmiddleware
so when a user subscribes to this profile, the Middleware will be triggered and the NFT minted will have the specified Token URI.In this example we are setting the
subscribePaid
middleware which will require the user to pay a fee to subscribe to the profile.
To view a full list of supported middlewares check out the Middleware guide.
caution
This API requires Authorization
header with the Bearer
token. You can learn more about it here.
Second, once you received data in a readable format, you’ll need to get the user’s signature for it. Basically, you’ll need to write a function and pass it a
message
as a param and return thesignature
that it’s necessary for the next step.Third, you’ll have to call the
relay
API that will broadcast the transaction and interact with the smart contract setting the middleware, you will need to put as params thetypedDataID
you received fromcreateSetSubscribeDataTypedData
mutation call and the user'ssignature
.
caution
This API requires Authorization
header with the Bearer
token. You can learn more about it here.
You can now verify the transaction by looking up the txHash
from the response on etherscan.io. That’s it! You’re all done!
Experiment in Sandbox
We’ve created an example that incorporates all the steps for Set Middleware for Subscribe. Feel free to experiment with our code in the sandbox below.