0

I am developing an ETH game with a referral structure. Each account that exists in the game has a "Referral Count" associated with it that updates as people sign up using their referral link. I am able to call and view this number thru the contract for each individual address.

Here is where I got stuck however... How can I display the "ref count" and "address" of the current highest referrer in the website UI? Can I do this completely through JS?

This is my first somewhat complex dapp so any pointers in the right direction would be much appreciated!

0

You would need a list of all addresses and then fetch each ref count for every address. This first of all only works if you have a list of all addresses and second of all is very bad for performance.

The best solution in your case is to keep track of the highest ref count and its according address. Whenever the ref count from an address is updated, check if its higher than the current highest. If yes, update it.

In general you could also use something like The Graph. It would allow you to analyze blockchain data and make it available to your frontend app. But this really is overkill for your use case.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.