Guild.xyz hook
By leveraging a new kind of smart contract hook, you can easily create all kinds of allow-list on your lock using Guild.xyz.
The Unlock Protocol has a unique feature that lets developers change the behavior of an Unlock membership contract while still leveraging most of its logic. These additional pieces of functionality are accessed via “hooks”. One of the hooks is the onKeyPurchaseHook
and it is triggered when new members are purchasing a membership NFT.
One of the most frequent feature requests for Unlock has been the ability to restrict who can purchase a membership. Last year, we introduced a CaptchaHook which requires users to go through a Recaptcha validation and prevents bots from being able to buy NFTs in bulk. We also introduced a hook to require a password when going through the checkout.
But we are still seeing demand for a more flexible approach, where a smart contract administrator (who is called a “lock manager” in the Unlock ecosystem) wants to only allow people in a specific allow-list, or people who own a certain amount of a specific token, or even users who have minted an NFT of a special kind to have access to mint or claim a membership.
Rather than build this complicated logic ourselves, we partnered with our friends at Guild.xyz to build a general-purpose Guild Hook! With the Guild Hook, a lock manager can point to any Guild they created and Guilds are extremely flexible!
Let’s go ahead and create an example!
Guild and Unlock Protocol integration using the Guild Hook
Let’s say I only want people who follow Unlock on Twitter to be able to claim a membership from this membership contract.
- First, I will go to Guild.xyz and create a Guild whose requirement is to follow Unlock on Twitter.
- Then, once the Guild has been created, I come back to the Unlock dashboard, go to the advanced settings for my lock, and select the Hooks section.
- I can then save the changes and my membership contract is now hooked to the Guild of the Unlock Protocol followers on Twitter!
Now the requirements are set, and there is one more step to go.
The last step is to build a checkout URL, like this one, through which users are prompted to join the Guild if they are not already members. Once someone is a member of the Guild, they can mint their NFT membership!
Like always, we’re excited to see what creators, conference organizers and others are doing with this! We also want to inspire developers to create more hooks that can change the behavior of the lock contract based on their own needs and requirements!