Set Essence Middleware
Workflow
Set middleware for essence 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 collecting an essence.
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
createSetEssenceDataTypedData
API that takes care of this.If you’re unfamiliar with typed data, you can read more about it here.
This API sets/updates the parameters for the essence such as
tokenURI
andmiddleware
so when a user collects this essence, the Middleware will be triggered and the NFT minted will have the specified Token URI.In this example we are setting the
collectPaid
middleware which will require the user to pay a fee to collect the essence.
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 fromcreateSetEssenceDataTypedData
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.