Password Required

Using a smart contract hook, it is now possible to require users to enter a password when they are making purchases, ensuring that only your community can purchase memberships!

By Julien Genestoux on

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.

Password Protected

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

Example

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!

Password Required!

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.

  1. First, you need to choose a password, then go to this page to generate the corresponding Ethereum address.

Generate Signer!

  1. 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 Contract > 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.

Set Signer!

  1. Finally, you need to point your lock to the hook. Using your lock's block explorer page, click on Contract > Write as Proxy. Connect your wallet (you need to be connected as a lock's manager) and look for setEventHooks. In the _onKeyPurchaseHook enter the address of the hook (from the list above), and enter 0x0000000000000000000000000000000000000000 for all the other hooks (unless of course, you want to use them...).

Set Hooks!

  1. Build a Checkout URL and make sure you include the "password": true option in it so that users are prompted for the password when they go through the checkout flow!

Developers

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!

You can find the code for this password-protected hook on Github as well as the tutorial in our docs.