简体   繁体   中英

How to check function is payable or not?

How to check in code (on Solidity side or/and Web3 side) before call contract function, this function is payable or not?

For example I found this today in token EURS

function transfer (address _to, uint256 _value)
public payable returns (bool success);

This is not standard make erc20 transfer function as payable!!! And this is not standard logic make bugs in my app, if user use EURS token.

This is standard

function transfer(address to, uint tokens) public returns (bool 
success);

So I need, or override this is no standard transfer on my app contract side, or in worst case do ban such tokens on frontend side.

To answer your question in one line-:

Any function which is marked as payable can be considered to receive ethers.

function testPayable() external payable {...}

The above function is payable and hence can receive.

But make no mistake payable keyword is only used to receive Ethers and not ERC20 tokens.

So in your case as far as I can see the transfer function is marked as payable, which should not be the case if it is ERC20 token.

Something sounds fishy to me, isn't it to you?

In one line: there is no way to check externally or from within solidity if a function is payable or not without knowing the abi / interface .

What is payable?

  • Payable works like any other modifier in Solidity. It runs just before executing the function it is applied on.
  • Payable is required to receive ether. If you send ether in a transaction to a non-payable function the transaction is reverted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM