How to Get Outstanding Referral Counts
Tracking the status of referrals is a key part of managing user onboarding and rewards on the Toto Chain. "Outstanding" referrals can mean two different things:
A pending referral you have received from someone else that you have not yet accepted.
The total count of referrals you have sent to others that they have not yet accepted.
The referral pallet provides direct and indirect ways to get both of these pieces of information. This guide explains how to do so using the Polkadot-JS Apps UI.
1.0 Checking for a Pending Referral You Have Received
This is the most direct query. The chain stores a list of pending referrals where the key is the person who was referred (the referee). You can directly check if your account has a pending referral waiting for it.
Method of Procedure (MOP)
Connect to the Node: Open the Polkadot-JS Apps UI and ensure you are connected to your local Toto Chain node (e.g.,
ws://127.0.0.1:9944).Navigate to RPC Calls: Go to the Developer -> RPC Calls section in the UI.
Execute the RPC Call:
Select the
referralpallet from the "submit the following extrinsic" dropdown.Select the
getPendingReferral(accountId: AccountId)RPC call.In the
accountIdfield, select your own account address from the dropdown. This is the account you want to check for pending referrals.Click "Submit RPC call".
Interpret the Results:
If the result is
null: You do not have any pending referrals waiting for you to accept.If the result is an AccountId (an address): You have a pending referral, and the address shown is the account of the person who referred you.
2.0 Counting Unaccepted Referrals You Have Sent
The pallet does not provide a single, direct RPC call to get a count of all the unaccepted referrals you have sent to others. This is because the primary storage is indexed by the referee, not the referrer.
To get this number, a client-side application (like a dApp front-end or a script) must query all pending referrals and filter them.
The Logic
The process involves these steps:
Query the Entire
PendingReferralsMap: A script would use an RPC call likestate_getPairsor a library-specific function to query all entries in thePendingReferralsstorage. This returns a list of all[referee, referrer]pairs currently on the chain.Filter by Your Account: The script would then iterate through this entire list. For each pair, it would check if the
referreraddress is your own account address.Count the Matches: The script would keep a running count of every entry where your address appears as the
referrer.
The final count is the total number of unaccepted referrals you have sent.
Last updated