0

I'm developing a point system and I'd like to do it with ERC-20 tokens...

All clear for me to "distribute the points/tokens" to wallet addresses that perform certain tasks, but then, my business rule, also have "penalty", where wallet address should loose points/tokens...

How can I achieve this? When I distribute a token, it cannot be "removed" from a third party address.. Right?

What would you do?

Thank you

1

On top of my head - are you going to use your custom ERC20 token? If yes, then just in the transfer method add condition for the user to transfer only tokens are not locked ( token amount that user does not have penalty for ). On each transfer the condition will check if the token amount that has to be sent is equal or smaller than the user unlocked balance.

If you're using already deployed ERC20 token then you cannot forbid the user to use the token amount that should be banned. You can forbid the tokens to be used in another smart contact, but you cannot disallow the user to send the tokens from one wallet address to another.

5
  • Thank you for your suggestion. I will create a custom token, therefore I'll look into the transfer options... potentially all points/tokens can be gained and lost... and at the same time, they should also be potentially be pur un a dex
    – FiNaR
    Dec 12 '20 at 6:39
  • Ok then if you're creating a custom token then you have to add new mapping mapping (address => uint256) bannedBalances;, new get method called bannedBalanceOf and the banning method which has to decrease user balance and increase the banned balance. If I helped you, please accept this answer with the green check so people having the same question can see this answer. Dec 12 '20 at 6:59
  • thank you Miroslaw.... I kind of getting the concept, but unsure how to proceed from here... 1) I create my custom ERC-20 Token 2) in the creation code I need to ensure I include a 'mapping (address => uint256) bannedBalances;' -> sorry for the stupid question, is there an existing method/function 'bannedBalanceOf' or I need to create it? 3)once created the toke, if I distribute it to ETH wallet addresses what I user can do with that? can they transfer them to other wallets? how will I "remove the tokens" if s user "gets penalties?
    – FiNaR
    Dec 13 '20 at 7:33
  • Let's clear out something - my proposal is not removing tokens from users wallets, but locking them. If you don't know the users private keys ( which is the case atm ) there is no way that you can remove tokens from their wallets. And it's better for your app security to not store any private keys! Dec 13 '20 at 13:39
  • Such logic as locking tokens is not typical for ERC20 and it is not included in the standard, you have to code it by your self. Usually in ERC20 tokens standard there is only one mapping called balances, now you have to add second mapping called lockedBalances. So users will have at the same time locked and unlocked balance. When you have to penalty someone just decrease his balance and increase his locked balance. And in the transfer method add condition to check if user has enough balance ( unlocked balance should not be included in this condition ). Dec 13 '20 at 13:44
0

You have to separate your concerns.

Generally speaking, tokens that are transferred are beyond your control. So, if you want to slash balances you should hold the staked tokens in your own contract and treat it as an internal accounting concern starting with deposit and withdraw functions and a structure to store your contract's liabilities:

mapping(address => unit) public playerTokenBalances;

In that simple pattern, tokens in your contract are "in play" and tokens withdrawn are safely in the hands of the holders - safe from the possibility of slashing penalties. There is no function you can write that will spend tokens in another wallet without consent.

It may be sufficient to conceptualize the reward system so that people will prefer to leave their token (claims) in your contract most of the time. And, since it's your contract, those balances would be subject to your rules.

If you find that insufficient for your use-case then the possibility exists to create a non-standard ERC20 token contract that implements some behind-the-scenes logic. ERC20 is, strictly speaking, a standard interface and a minimal set of behaviors that must be implemented but is not the limit of the functions that can exist or the logic that unfolds inside the contract.

Such a special implementation would have be very carefully considered, so it is usually best to prefer the first option.

Hope it helps.

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.