当调用智能合约方法时,是如何计价的?

2018/06/09 22:51
阅读数 136

There are estimateGas APIs in both the JSON-RPC and Javascript.

They are estimates and for developers that want further precision, testing is required, possibly on a private chain.

If too much gas is provided, the excess gas is converted to ether and refunded. If too few gas is specified, all the specified gas is forfeited to the miner and the transaction is reverted: just like the contract was never called.

Users will generally have to trust the DApp they are using, and DApps that have good UI and UX, may indicate some estimated costs to the user, or possibly even hide such details by sending the user's account some ether, or giving a new user an account that has some ether.

This is feasible because most transactions require a very small amount of ether; 1 ether is 10^18 wei and can run many transactions. As an example, if one were simply using Ethereum to transfer wei/ether around, at the current gas price of 5 Gigawei, a user can do around 9523 transfers with 1 ether. This is because a value transfer transaction costs 21000 gas, and thus the computation is 1e18 / (21000 * 5e9) = 9523.80.

上文主要意思是有Javascript方法(或RPC方法)进行对交易预先进行评估价格,主要是eth_call参数的定义,里面涉及到ABI方法的hash值,依此就知道是调用哪个方法了,然后进行估价。一般会高一些,因为EVM内部其他消耗,如果算多了,交易后会退回。如果给少了,已经给出的gas将丢失(给了挖矿执行的人,因为人家已经尝试执行了),交易回滚。

  • dataDATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部