简体   繁体   English

如何检查功能是否应付?

[英]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? 什么是应付款?

  • Payable works like any other modifier in Solidity. 应付账款与Solidity中的任何其他modifier一样。 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. 如果您将交易中的以太币发送到非应付函数,则会还原该交易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 HardHat 调用可支付的 Solidity 函数? - How to invoke a payable solidity function using HardHat? 叫function突然需要应付 - Called function suddenly needs to be payable 如何测试 Solidity 应付合同 - How to test a Solidity payable contract 如何在Web3 v1中使用带有ERC20令牌的应付款功能 - How to use a payable function with a ERC20 token with web3 v1 如何解决错误“function 调用中的参数类型无效。请求的地址到应付地址的隐式转换无效” - How to resolve the error "Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested" 撤回 function 发送仅适用于“应付地址”类型的对象 - Withdraw function send is only available for objects of type "address payable" 不能使用后备。 什么都没发生! 函数()外部应付{} - Can't use fallback. Nothing happen! function() external payable {} 如何在solidity 0.5.2或更高版本中分配或重置address[]payable变量? - How to assign or reset the address[] payable variable in solidity 0.5.2 or above? 我们可以在实施ERC721令牌的同时将应付款修改器添加到转移功能吗? - Can we add payable modifier to transfer function while implementing ERC721 token? 可靠性:调用另一个合约的函数时出错。 错误:发送值时应向构造函数付款 - Solidity: Error when calling a function of another contract. Error: The constructor should be payable when you send value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM