This guide shows you how you can use the powerful hook mechanism to password-protect your lock so that only users who know the password can purchase memberships from your contract.
Generate a signer address
Let’s start with a quick example: you are not able to purchase a membership for this lock without entering a secret password during the checkout process. For this example, the password is sek3e+-pass30rD.
First, you need to pick a password: it can be anything as long you keep it secret! Then go to this page to generate an Ethereum address that corresponds to the password. The address itself does not have to be secret, but is also not particularly useful to anyone who knows it: they can’t “guess” the password from the address.
Set the signer on the hook
We have deployed the hook in multiple networks; click on the network of your lock:
This video shows you how to do all this:
Connect your lock to the hook
This is the final step on the smart contracts. We will use the block explorer again, but this time with your lock contract. From the Unlock dashboard, click on the block explorer link for your contract. There, once again, click on Contract and then Write as Proxy. Connect to your web3 wallet.
Look for the setEventsHook function. This function lets you connect your lock to other contracts that modify its behavior. Here we are connecting your lock to the password verification hook. In the first field, enter the address of the hook on the right network (you can find them from the list above). In the other fields, please enter 0x0000000000000000000000000000000000000000 as you don’t want to use the hooks. Hit the Write button and confirm the transaction!
The video below shows you how to do it:
Build a Checkout URL
Your lock is now password protected! However, you need to configure the checkout flow so that users can enter the password; otherwise, they won’t be able to make purchases.