3

I have to create and transfer token using ERC 20.Inside the standard interface of ERC 20, we have function approve(address spender,using token) which inturn approves spender to take some token from (msg.sender). My question is that can we specify some other account address which we wish to transfer from instead of (msg.sender)..?? (i.e can we pass an extra parameter for the function approve like approve(address owner,address spender,uint token)...??)

4
  • 1
    Welcome to the Ethereum Stack Exchange! You have to be careful of how you're thinking of modifying approval because you don't want a hacker to be able to call approve(HariAddress, hackerAddress, 1000) and steal 1000 of your tokens... The standard approval protects you because Hari (msg.sender) has to call approve for Hari's tokens to be spent.
    – eth
    Commented Sep 11, 2018 at 11:02
  • if you don't implement the functions exactly as they were designed, my explorer will show you as "non-compliant" token. And if you add extra parameters to the functions, your contract won't be considered as ERC20 token at all and won't be listed in the wallet.
    – Nulik
    Commented Sep 12, 2018 at 19:57
  • I created an ERC20 contract and tried to send some ETH. The contract shows the amount of ETH I sent but I cannot find it on my wallet. Why is that?
    – Jems Ack
    Commented Jun 10, 2019 at 17:41
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Ismael
    Commented Jun 10, 2019 at 18:46

2 Answers 2

4

If you wish your token to be ERC20 compliant you have to have the required functions with the required signatures. That's the whole point of the standard.

However, that leaves you with two other options:

1) Add more functions and/or contract variables. You can add whatever functions you wish with whatever signatures and functionality you wish as long as the required ERC20 signatures also exist in the contract.

2) Do whatever you want inside the required ERC20 functions. ERC20 can be considered only as an interface - it doesn't tell you how to implement the functions, only enforces you to have certain functions in the contract. You can for example add some data with a custom function and in the required approve function use the data in some way.

2

If you do so, you will no longer be an ERC20 token.

An ERC20 token must expose the defined methods with the exact same signatures. This means you cannot change the parameters or names.

You can add modifiers, or update the code inside the function (as is done by various implementations of pausable tokens, and other extended tokens).

If you wish to define an additional method, you can do so, but your original approve() method must retain its parameters.

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.