How to use Moralis for a referral or affiliate program?

I see that each user that connects with meta mask will create a user id as their username if none is set.

Currently I am having the user be able to set their username and this information is stored based on the addresses that the user has connected with a given account, I have also noticed if a new address that has connected tries to set a username already in use it will not work.

So I am trying to see is it possible to use the username as a query string (example.com/?ref=username) to be included when a new user connects their wallet and keeping record that x-user has referred them?

Also if then a query to the database could also be made for that users referrals and to then filter by only referrals that have interacted with a specific smart contract with a specific function to then reward that user for the referral?

I know its a bit confusing, but I don’t just want to reward referrals for visits or signups, but actually doing something on the dapp such as interacting with it or calling a specific function.

I think this might be able to work by passing this data to the login script similar to how I’ve seen Ivan do it for creating a new user with data already populated. But not sure how to do it in this fashion?

1 Like

Hey @odappsdev
Welcome aboard!

  1. Please share the code and the error message.

I have also noticed if a new address that has connected tries to set a username already in use it will not work

  1. One option is to change the welcome message. And then, when interacting with smart contracts, receive information about referrals.
Moralis.Web3.getSigningData = () => 'Welcome! Ref 0x3432fdsdskdksdskdk'

This message will be stored in the database in the user object.

Hope this help :sunglasses:

1 Like

It was not an error as it is to be expected that 2 users can not share the same username.

I think it will allow me a good starting point, thank you!

Happy BUIDLing :man_factory_worker: