A fairly common request by event organizers and creators revolves around selling memberships in a password-protected way: only those who know the password can purchase.
Today, we’re excited to announce how creators can easily use their membership contract (a lock), a hook, and our checkout URL flow to password-protect purchases.
Of course, this process is secured and cannot be bypassed by calling the contract directly, as the password is used to submit the transaction on-chain. Additionally, the password is not transmitted “in the clear” to ensure that it remains secret but used to sign the recipient’s address, making the transaction unique for each user.
The hooks were deployed on the production networks (and can easily be added to more).
This lock deployed is deployed on Goerli and uses this password hook. This means you can only purchase a key if you go through this checkout URL and if you enter the right password:
sek3e+-pass30rD. Please try with a bad password first!
Using the hook for your own lock
Adding a password to your lock requires the use of a hook. Hooks are a very powerful mechanism used to alter the behavior of your lock. Here is a quick guide and you can find a longer version in our Guides.
- First, you need to choose a password, then go to this page to generate the corresponding Ethereum address.
- Then, click on which network your lock has been deployed on (list here) to go to the block explorer page for the hook and head to
Write Contract. Connect your wallet (you need to be connected as a lock's manager) and click on
setSigner. There, enter the lock address and then the wallet address generated in the previous step.
- Finally, you need to point your lock to the hook. Using your lock's block explorer page, click on
Write as Proxy. Connect your wallet (you need to be connected as a lock's manager) and look for
setEventHooks. In the
_onKeyPurchaseHookenter the address of the hook (from the list above), and enter
0x0000000000000000000000000000000000000000for all the other hooks (unless of course, you want to use them...).
- Build a Checkout URL and make sure you include the
"password": trueoption in it so that users are prompted for the password when they go through the checkout flow!
Even though this hook is “readily” usable, exactly like our “bring your own contract” hooks created a few months ago, we felt that it was a very good example of how to create hooks for your smart contract. As such, we created a dedicated tutorial that you can refer to see how we created it and use that as an inspiration to create your own hooks!