@emilianobonassi/referral v1.0.0
Referral is a collection of smart contracts and utilities to implement on-chain referral marketing strategies.
How it works
It defines the modifier referral
that you can use to track referrals and reward referrers on and off-chain.
When a user is advised for the first time by a referrer the event NewReferral(address indexed referrer, address indexed user)
,
you can use this to track to how many user a specific referrer promoted your initiative.
You can use _hasReferrer(address user)
to check if the user
was invited by a referrer.
To get the latter, just query mapping (address => address) referrerForUser
using user
.
In some cases, you would like to know if a user was just referred in that specific tx, you can use the boolean field _justReferred
.
Usage
Simply add the modifier referral
to the methods you want, specifying the user
that is advised and the referrer
.
Below an example with SimpleReferral.
import "@emilianobonassi/referral/SimpleReferral.sol";
contract MyContract is SimpleReferral {
...
function subscribe(bytes subscriptionData, address referrer)
external
referral(msg.sender, referrer)
returns (bool) {
...
}
...
}
4 years ago