Unlock Guides

Back

Password Protected NFT Memberships

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.

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 processFor 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.

Generate signer address from password
Generating the signer address from the password

Set the signer on the hook

We have deployed the hook in multiple networks; click on the network of your lock:

  • Ethereum : 0x936Ed3E71b5990bC9A94074835D08C6ca7bbFad0
  • Polygon: 0x9F4AE507d7E91Ab37CF35f792940fE079bd4E24d
  • Gnosis Chain: 0x927D68eAE936Ec0111f01Fc4Ddd9cC57DB3f0Af2

You can find the full list on the code repository and please, reach out if you need to use it on other networks.

Once on the block explorer page, click on Contract, and then Write Contract. Click on Connect to Web3 link to connect your wallet: make sure you use the wallet that is a lock manager for the lock you want to connect! Then, look for the Set Signer function, and enter both the lock address and the signer address that you generated on the previous step. Make sure you click the Write button to confirm the transaction.

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.

For this, you will need to configure the Checkout URL

Was this article helpful?
YesNo

In order to follow this guide, please start by deploying your lock. Additionally, please make sure you verify the lock’s contract using the block explorer so you can easily interact with it!

Table of Contents