[英]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? 如何在呼叫合同功能之前签入代码(在Solidity方面或/和Web3方面),这个功能是否可以支付?
For example I found this today in token EURS 例如,我今天在令牌EURS中发现了这一点
function transfer (address _to, uint256 _value)
public payable returns (bool success);
This is not standard make erc20 transfer function as payable!!! 这不是标准的erc20传输函数应付!!! And this is not standard logic make bugs in my app, if user use EURS token.
如果用户使用EURS令牌,这不是我的应用程序中的标准逻辑错误。
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. 但不要错误应付关键字仅用于接收Ethers而不是ERC20令牌。
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. 所以在你的情况下,据我所知,转移功能被标记为应付款,如果它是ERC20令牌则不应该是这种情况。
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 . 在一行中:如果在不知道abi /接口的情况下是否支付功能,则无法从外部检查或从内部检查。
What is payable? 什么是应付款?
modifier
in Solidity. modifier
一样。 It runs just before executing the function it is applied on.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.