GithubHelp home page GithubHelp logo

ccarfi / discount-hook Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unlock-protocol/discount-hook

0.0 0.0 0.0 105 KB

A Hook for the Unlock Protocol locks that lets lock manager add discount codes.

TypeScript 63.59% Solidity 36.41%

discount-hook's Introduction

Discount Hook for Locks

This project implements an Unlock PublicLock Hook that can be used on Locks smart contracts to support "Discount Code".

This process is secured and cannot be bypassed by calling the contract directly as the discount code is used to submit the transaction on-chain.

When the user enters a discount code on the frontend application, it is used to generate a private key that is then used to sign the recipient's address. That signature is passed as the data argument on the purchase call.

A lock manager can add any number of discount code to their lock by calling the function setDiscountCodeForLock.

The Unlock Protocol team has deployed and verified a version of this hook on the following networks:

Production networks:

Test networks:

Example

This lock deployed is deployed on Goerli and uses this discount hook with 2 different discounts:

  • FRIENDS for a 50% discount
  • FAMILY for a 100% discount

This means you can only purchase a key if you go through this checkout URL and enter any of the 2 discount codes you will see a discounted price on the final confirmation screen!

If you don't enter a discount code, you will pay the full price of 0.01 Eth.

Using the hook for your own lock

  1. First, you need to generate promo codes, then go to this page to generate the corresponding Ethereum address. You can also generate this locally if needed by checking out the repo and switching to the gh-page branch.

Screen Shot 2023-01-09 at 12 55 04 PM

  1. Then, click on which network your lock has been deployed on (list above) and head to Contract > Write Contract. Connect your wallet (you need to be connected as a lock's manager) and click on setDiscountForLock. There, enter the lock address, and then the signer address generated in the previous step and the discount to be applied. Since the EVM does not support floating numbers, you have to enter the value in "basis points". For example for a 100% discount, you would enter 10000. For a 3% discount, you would enter 300.

Screen Shot 2023-01-09 at 12 56 45 PM

  1. After that, you need to point your lock to the hook. You can do that by going to your lock's settings page on the Unlock Dashboard. Then check the Advanced tab and the Hooks section.

Screen Shot 2023-01-09 at 12 57 19 PM

  1. Finally, build a Checkout URL and make sure you tick Promo Codes option for the lock to which you are applying a discount!

Screen Shot 2023-01-09 at 12 57 52 PM

Dev

You can deploy the hook on other chains by adding the chain to the hardhat.config.js config file and calling:

yarn run hardhat run scripts/deploy.js --network my-network

To verify the contract on block explorers, call :

yarn run hardhat verify --network my-network 0xhook-address

Running tests:

yarn run hardhat test test/sample-test.js

discount-hook's People

Contributors

julien51 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.