1

I'm in a situation to implement the following scenario:

  • Need to transfer ERC20 standard token(own by my contract) to some another wallet.
  • When recording transaction on Ethereum, need to add custom data(eg: why this transaction happens.)
  • When executing getBalance method on any wallet address it should be able to read custom data as well.

Is there any way that I can add custom data on transactions while maintaining the ERC20 standard? Appreciate any help.

3 Answers 3

1

The ERC20 standard explicitly tells you that you can't modify the default function signatures. Therefore you can't directly add extra data to those function calls.

However, you can call a different custom function which saves some data AND calls the ERC20 transfer function. Similar thing when calling the getBalance function.

These custom functions won't of course be recognized by the ERC20 standard but whoever knows of them can use them. They just need custom implementation. So there is no way for ERC20 implementers (such as an exchange) to call your custom functions (they have no reason to implement it).

0

You may be able to achieve what you want by extending your contract to have methods and behavior beyond that required by the ERC20 standard.

For example, if you need to log additional information when a transfer occurs you can do this by adding a custom event which you emit in addition to the required Transfer() event.

Likewise, for returning custom data, you may not modify the required getBalance() method, but you can add an additional method, such as:

getAdditionalInfo()

You can define this method to return whatever data you like.

Of course those who take advantage of these extra features will need to do so based on their knowledge of how your particular token works. Anyone who wants to just treat your token as a generic ERC20 token is of course still free to do so.

0

Thanks to @lauri-peltonen - I had the same question, so does anyone have an example on say Github where they have added additional info?

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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