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)...??)
2 Answers
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.
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.
approve(HariAddress, hackerAddress, 1000)
and steal 1000 of your tokens... The standard approval protects you because Hari (msg.sender) has to callapprove
for Hari's tokens to be spent.