💰X-to-Earn Design Pattern
X to Earn
Intro
It's now common practice to reward your users/fans/following for positive behavior. Game-to-earn, Social-to-earn and even Step-to-earn takes only minutes to set up on XP Protocol.
The key to this design pattern is in the Idompotency of the updateId parameter of the updateScore() method.
Repeatable Actions
Great for use with "Liked", "Saved", and "Posted". Types of Actions that a user should perform regularly
Below is a great example of an updateId for an action that a user will do often. Notice how the string remains static except for the last edition of the unix time.
The Unix time in milliseconds attached to the end of the string will ensure that this updateId will always change each time a user performs that action.
Full Example
Semi-Repeatable Actions (time-based)
Sometimes you will also want to reward your users for time based actions, such as a "Daily Login".
Typically as a developer, you would have to track each day that your users log in and ensure that you do not accidentally give them that reward more than once in a 24h period.
Because XP has built-in Dedupe capabilities, you no longer need to keep track of that.
This can be achieved with "Semi-Repeatable Actions", this design again simply relies on how we construct the updateId.
Notice how the dayNumberSinceEpoch will change every 24h. This allows you as a developer to not worry about storing and tracking the reward, you can simply let an updateScore() transaction fire upon a "Login" event on your platform, and know that it will only be counted toward that user's score every 24h.
Last updated