2

How to make payable function to receive tokens and not ether?

2

The payable modifier allows a function of a contract to receive ether.

Tokens work entirely differently to ether as they are just numbers registered against addresses in a token contract. They never leave the token contract and any transfers are entirely contained in the contract

Another contract that seeks to have payments made to it in tokens, must be aware of the token contract itself in order to interact with it. Even then a token payment to that contract is made by normal token transfer:

<erc20address>.transfer(<other_contract_address>, <amount>)

It's then up to the other contract to somehow be aware of that transaction. Such a contract may be written to rely on the transferFrom() function in which the token hold calls approve() on the token to give the contract permission to move tokens. The user then might be able to interact with that contract's token payment functions for whatever and however they've been written.

0

There is no way that payable function receives ethereum tokens. Ethere's fuel is ether, not token, so what you do to change status would coast ether. This article shows the difference between ether and token.

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.