0

ERC20 token interface has the approve function

approve(address spender, uint amount)

Is there any function, where the contract itself can approve its tokens for another address?

Something like this approveFrom(address thisContract, address spender, uint amount)

2 Answers 2

0

approve its tokens for another address?

This isn't very clear. "Its" could mean tokens the contract wants to spend or tokens the contract wants to receive.

@Laurie is exactly right if it's the former case. The contract can spend its own money just like anyone include authorizing another contract to transferFrom().

If you want the latter case, e.g. The contract wants to "approve" the transfer of Alice's tokens to itself, then no, this is not the intended behaviour. Having said that, anyone can implement a token with novel rules but such a "feature" would be controversial and probably not acceptable to most token holders.

Hope it helps.

0

Even if the ERC20 standard doesn't dictate how the token contracts should be implemented, almost always the approve function approves spender to spend tokens from msg.sender.

So if you use that function from a contract the msg.sender will be the contract - therefore, if I understood your question right, it works just as you wanted.

So it's always the token holder who has to approve the token transfer (in advance).

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.