首页 > 解决方案 > 无法估计执行时的气体

问题描述

我在调用函数并在另一个实例中发送同一合约的资金时遇到问题:

function buyLoan(address _sellLoan, address _sellPortfolio) public {

    uint tradePrice = Loan(_sellLoan).getBalance();

    // Now check if funds available
    if (tradePrice > address(this).balance) {
        // Not enough funds, so revert
        revert();
    } else {
        // Enough funds, so execute purchase

        // Get Sell Portfolio for transfer
        Portfolio sp = Portfolio(_sellPortfolio);

        // Finalize sale of Loan
        tr.executeTrade(_sellLoan, _tradeDate);

      if (!address(sp).send(tradePrice))
            revert();

        // Now add loan to buying portfolio
        addLoan(_sellLoan, tradePrice);

        // Delete loan from selling portfolio
        sp.deleteLoan(_sellLoan);
        }

}

当我尝试运行这个函数时,我得到一个错误,它无法估计所需的气体。代码编译并且没有 do while 或 for 循环。

我遇到的问题是我什至不知道在哪里可以解决这个问题......

确切的错误是:

气体估计错误并显示以下消息(见下文)。事务执行可能会失败。是否要强制发送?JsonRpcEngine - 响应没有错误或请求结果:{“jsonrpc”:“2.0”,“id”:2522037241,“method”:“eth_estimateGas”,“params”:[{“from”:“0x6d4dcc21e77ee5bc18d0f91497fc5285a71c836a”,“to ": "0x1B15f071B4Fbd625Ebb3cC389D856ea2Ba7284A5", "data": "0x03fb6eb00000000000000000000000006f13ee53f5eced4021b768c2949f45c5075120890000000000000000000000001b15f071b4fbd625ebb3cc389d856ea2ba7284a5", "value": "0x1001d1bf800" } ] }

我正在使用版本 ^0.4.25 进行混音编译。我将不胜感激您能给我的任何帮助。

谢谢。

标签: solidityremix

解决方案


现在这个问题已经解决了。问题是使用send时预留的gas不足(即2300)。使用 call as Smarx 在这里帮助了我:

https://ethereum.stackexchange.com/questions/65879/error-when-executing-transfer-with-sufficient-funds?noredirect=1#comment79515_65879

关键是命令:

address(sp).send(tradePrice)

应该:

address(sp).call.value(tradePrice)("")

无论如何,感谢所有回应并试图提供帮助的人。


推荐阅读