Referral Library
Referrals are one of the most effective forms of marketing to gain exposure and drive users to your DApp. Lots of popular DApps such as Fomo3d, MyCrypto Heroes, HyperSnake, as well as many others use referrals as a mechanism for success.
Hence, we've built a referral library: Referral Solidity, to help DApp developers to quickly build their own referral mechanisms. In this document we will share how to use our library.
Referral Solidity Library Check out our basic multi-level referral: https://github.com/thundercore/referral-solidity/. With this library, you can gain the following features in minutes:
Up to three levels of referral system with native token (ETH,TT...)
Pay referral bonus based on referee amount
Pay instantly when downline joins
Ensure that only active users will get the referral bonus
How to use First, install our library with the following command.
Then, integrate referral solidity with your DApp by importing, initializing, binding referral relationship with addReferrer
function and trigger referral payment by payReferral
.
In the line of constructor() Referral (10000, 500, 1 days, true, [6000, 3000, 1000], [1, 10000])
. You may be confused what these parameters mean, thus please refer to the explanation for the parameters below:
decimals <unit>
Base decimals for all rate calculation in referral. For example. if decimals
equals to 10000
, and referralBonus
is 500
, that means the referral bonus rate is 5%
.
referralBonus<unit>
The total referral bonus rate, will be divided by decimals
. For example, if you would like to set a rate of 5%
, then set referralBonus
as 50
when decimals
is 1000
.
secondsUntilInactive<unit>
How long, in seconds, a user will be inactive. For example, one days
.
onlyRewardActiveReferrers<bool>
The flag to enable whether not to pay inactive uplines.
levelRate<uint[]>
The bonus rate for each level, which will be divided by decimals. For example, if the max depth level is 3, then the set levelRate as [6000,3000,1000]
when decimals
is 10000
for the following case:
refereeBonusRateMap<uint[]>
The bonus rate mapping to each referree amount will be divided by decimals too. If the max depth is 3, the map should be passed as [<lower amount>
,<rate>
,...]. For example, you should pass [1, 2500,5,5000,10,10000]
when decimals is 10000
for the following case:
Let's see an example to understand it better!
Example - Integrate to DoubleOrNothing
Let's add referrals to Double or Nothing! To do so we will need to set up the referral rules first:
A user would pay 3% for referral, in different referral levels would get 60%, 30%, 10% of 3%
A user gets 50% of referral bonus when they refer less than 5 people, 75% for less than 25 people, and 100% when over 25 people
A user needs to play within 24 hours to remain an active user, which means that if a user does not play once a day, this user cannot get the referral
So, assume: The referral sequence A ← B ← C ← D A has referrerd 25 people, B has 6 people and C has 1 person. When D bets 1TT, 3% of bet will go to the referral pool (0.03TT). Then each upline will get:
A: 1 * 0.03 * 0.1 * 1 = 0.003
B: 1 * 0.03 * 0.3 * 0.75 = 0.00675
C: 1 * 0.03 * 0.6 * 0.5 = 0.009
So the parameters we pass to constructor will be:
Now let's enable the referral!
Contract
First import and pass parameters to our referral contract:
Then, add overload bet function to bind referral upline when bet with the address.
Next, add payReferral in bet function
Finally, to deploy our DoubleOrNothing, we need to pass parameters in the migrations.
Frontend Now, you can get the referral data from public accounts in the contract, including the total amount of referees and the total referral bonus of a user.
Then, you can paste the URL to get referrer, likehttps://thundercore.github.io/DoubleOrNothing?referrer=0x26b067f40696c97a058658949ec011ed6a84afe3
. Then, trigger the smart contract by contract.bet(address)
to bind uplines and contract.bet()
for normal bet. The referral will pay directly when they bet.
For more information, please refer here.
Last updated