Referral.sol

The Referral contract's primary purpose is to facilitate a referral system within a dApp. This system motivates users to invite others to join the dApp and rewards them with commissions for succes

Read Functions

getReferrer

getReferrer

The function getReferrer is a public view function that takes an address parameter called _user and returns an address value. It is used to retrieve the referrer address that referred the specified user.

To use this function, users need to provide the address of the user for whom they want to retrieve the referrer address.

The function then accesses the referrers mapping using the _user address as the key and returns the corresponding referrer address.

If there is no referrer address associated with the specified user, the function will return the zero address (0x0000000000000000000000000000000000000000).

This function is useful for tracking and rewarding users who refer new users to the system.

  • Arguments

    NAMETYPEDESCRIPTION

    _user

    address

    The _user parameter is an address value that represents the user for whom the referrer address needs to be retrieved.

isReferralContract

isReferralContract

The function isReferralContract is a public pure function that does not take any arguments and returns a bool value. It is a getter function that is used to check if the contract is a referral contract. This function does not modify any state variables and does not require any prerequisites or conditions to be met. It simply returns a boolean value indicating whether the contract is a referral contract or not. Users can call this function to determine if the contract they are interacting with is a referral contract, which can be useful for implementing specific logic or functionality based on the contract type.

operator

operator

The function operator is a view function that returns the address of the operator. It does not take any arguments. This function is used to retrieve the address of the operator, which is the account that has the authority to perform certain privileged operations on the contract. The operator address is set using the updateOperator function, which can only be called by the contract owner. Users can call this function to get the address of the operator and verify its identity. Note that this function does not modify the state of the contract and does not require any prerequisites or conditions to be met.

owner

owner

The function owner is a view function that returns the address of the contract owner. It does not take any arguments. This function is used to retrieve the address of the owner of the contract. It is a read-only function, meaning it does not modify the state of the contract. Users can call this function to get the address of the contract owner. The returned address represents the current owner of the contract. There are no prerequisites or restrictions for calling this function.

referralsCount

referralsCount

The function referralsCount is a public view function that takes an address parameter called _user and returns a uint256 value. It is used to retrieve the total number of referrals made by a specific user.

The function first checks the state of the contract and retrieves the total number of referrals made by the _user address. It does this by accessing the referralsCount mapping using _user as the key. The function then returns the total number of referrals as a uint256 value.

This function is useful for tracking and displaying the number of referrals made by a user. It can be used by external applications or contracts to retrieve and display this information.

  • Arguments

    NAMETYPEDESCRIPTION

    input (address)

    address

    Number of referrer from an user

referrers

referrers

The function referrers is a public view function that takes an address parameter called _user and returns an address value. It is used to retrieve the referrer address for a given user. The function first checks if the _user address is valid and has a referrer associated with it. If the _user address is valid and has a referrer, the function returns the referrer address. If the _user address is not valid or does not have a referrer, the function returns the zero address (0x0000000000000000000000000000000000000000). This function is useful for retrieving the referrer address for a user, which can be used for various purposes such as tracking referral commissions or implementing referral programs.

  • Arguments

    NAMETYPEDESCRIPTION

    input (address)

    address

    No description

totalReferralCommissions

The function totalReferralCommissions is a public view function that takes an address parameter called _user and returns a uint256 value. It is used to retrieve the total referral commissions earned by a specific user.

The function first checks the state of the contract and ensures that it is in a view state, meaning it does not modify the contract's state. It then retrieves the total referral commissions associated with the given _user address by calling the totalReferralCommissions function with the _user address as the input parameter.

The function returns the total referral commissions earned by the _user address as a uint256 value. This value represents the total amount of commissions earned through referrals by the specified user.

Users can use this function to check the total referral commissions they have earned by providing their address as the input parameter.

  • Arguments

    NAMETYPEDESCRIPTION

    input (address)

    address

    Token earned using referreal

Write Functions

drainBEP20Token

drainBEP20Token

The function drainBEP20Token is an external function that allows the owner of the contract to drain tokens that are sent to the contract by mistake. The function takes three parameters:

  1. _token (address): This parameter represents the address of the BEP20 token that the owner wants to drain.

  2. _amount (uint256): This parameter represents the amount of tokens that the owner wants to drain.

  3. _to (address): This parameter represents the address where the drained tokens will be transferred to.

The function can only be called by the owner of the contract, as indicated by the onlyOwner modifier. When called, the function transfers the specified amount of tokens from the contract's balance of the specified token to the specified address using the safeTransfer function of the IBEP20 interface.

Users can use this function to recover tokens that were accidentally sent to the contract.

The function can only be called by the owner of the contract, as indicated by the onlyOwner modifier.

  • Arguments

    NAMETYPEDESCRIPTION

    _token

    address

    The _token parameter is the address of the BEP20 token that the owner wants to drain. This parameter should be a valid address of a BEP20 token contract.

    _amount

    uint256

    The _amount parameter is the amount of tokens that the owner wants to drain. This parameter should be a positive integer representing the number of tokens to be drained.

    _to

    address

    The _to parameter is the address where the drained tokens will be transferred to. This parameter should be a valid Ethereum address.

recordReferral

recordReferral

The function recordReferral is a public function that takes two address parameters: _user and _referrer. It can only be called by the operator.

The purpose of this function is to record a referral between two addresses. The function first checks if both _user and _referrer are not equal to the zero address and if they are not the same address. It also checks if the referrer for the given user is not already set.

If all the conditions are met, the function sets the referrer for the user by assigning the _referrer address to the referrers[_user] mapping. It also increments the referralsCount for the referrer by 1.

Finally, the function emits the ReferralRecorded event with the _user and _referrer addresses.

This function is used to establish a referral relationship between two addresses and track the number of referrals made by each referrer.

The caller of this function must be the operator.

  • Arguments

    NAMETYPEDESCRIPTION

    _user

    address

    The _user parameter is an address that represents the user for whom the referral is being recorded.

    _referrer

    address

    The _referrer parameter is an address that represents the referrer for the user.

recordReferralCommission

recordReferralCommission

The function recordReferralCommission is a public function that takes two parameters: _referrer of type address and _commission of type uint256. It can only be called by the operator.

The purpose of this function is to record a referral commission for a given referrer. The function first checks if the _referrer is not the zero address and if the _commission is greater than zero. If both conditions are met, the function adds the _commission to the totalReferralCommissions mapping with the _referrer as the key. It then emits the ReferralCommissionRecorded event with the _referrer and _commission as the parameters.

This function is used to track and record referral commissions for referrers. It is called when a referral commission needs to be recorded, typically after a successful referral or a commission payout.

  • Arguments

    NAMETYPEDESCRIPTION

    _referrer

    address

    The _referrer parameter is the address of the referrer for whom the referral commission is being recorded. It should not be the zero address.

    _commission

    uint256

    The _commission parameter is the amount of the referral commission being recorded. It should be greater than zero.

renounceOwnership

renounceOwnership

The function renounceOwnership is a public virtual function that can only be called by the current owner of the contract. It does not take any arguments.

The purpose of this function is to allow the current owner to renounce their ownership of the contract, effectively leaving the contract without an owner. Once ownership is renounced, it will not be possible to call any functions that are restricted to the owner.

When called, the function first checks if the caller is the current owner by comparing the caller's address with the _owner variable. If the caller is not the owner, the function will revert with the error message 'Ownable: caller is not the owner'.

If the caller is the owner, the function emits an OwnershipTransferred event with the current owner's address and the zero address (0x0) as the new owner. This event signifies that ownership has been renounced.

After emitting the event, the function sets the _owner variable to the zero address, effectively removing the owner from the contract.

transferOwnership

transferOwnership

The function transferOwnership is a public function that takes an address parameter called newOwner. It can only be called by the current owner of the contract. The purpose of this function is to transfer the ownership of the contract to a new account. The function first checks if the newOwner address is not the zero address, which means it is a valid address. If the newOwner address is valid, the function emits the OwnershipTransferred event with the current owner address (_owner) and the newOwner address. Then, the function updates the _owner variable with the newOwner address, effectively transferring the ownership of the contract to the new account. This function is useful when the current owner wants to transfer the ownership of the contract to another account, giving them control over the contract's functions and state.

The caller of this function must be the current owner of the contract. This is enforced by the onlyOwner modifier, which checks if the _owner variable is equal to the address of the message sender (_msgSender()). If the caller is not the owner, the function will revert and the ownership transfer will not occur.

  • Arguments

    NAMETYPEDESCRIPTION

    newOwner

    address

    The newOwner parameter is an address value that represents the account to which the ownership of the contract will be transferred. It must be a valid Ethereum address and cannot be the zero address (0x0000000000000000000000000000000000000000).

updateOperator

updateOperator

The function updateOperator is an external function that takes an address parameter called _operator. It is used to update the status of the operator.

The function first checks if the _operator address is not equal to the zero address. If it is equal to the zero address, it will revert with the error message '_operator should be non-zero address'.

If the _operator address is valid, the function emits an OperatorUpdated event with the current operator address and the new _operator address.

Finally, the function updates the operator variable with the new _operator address.

This function can only be called by the contract owner.

onlyOwner

  • Arguments

    NAMETYPEDESCRIPTION

    _operator

    address

    The _operator parameter is an address value that represents the new operator address to be set.

Last updated