solidity - 无法估计执行时的气体
问题描述
我在调用函数并在另一个实例中发送同一合约的资金时遇到问题:
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 进行混音编译。我将不胜感激您能给我的任何帮助。
谢谢。
解决方案
现在这个问题已经解决了。问题是使用send时预留的gas不足(即2300)。使用 call as Smarx 在这里帮助了我:
关键是命令:
address(sp).send(tradePrice)
应该:
address(sp).call.value(tradePrice)("")
无论如何,感谢所有回应并试图提供帮助的人。
推荐阅读
- sql - 如何从 PostgreSQL 数据集中的某个列中获取所有 MAX 值
- python - 绘制 scipy.optimize.differential_evolution 的收敛结果
- ruby-on-rails - 如何更改每 n 次迭代的代码
- r - R Shiny 数据分析:我正在努力从我上传的 .csv 文件中渲染一个图
- powershell - 使用@Splat 发送邮件附件结果,执行成功后删除
- c# - 从 Xamarin Android 中的 TimePicker 获取选定的时间
- css - ReactJS 和渲染问题
- regex - htaccess - 如何比较环境变量 - 检查2个环境变量是否相同
- react-native - React Navigation 5:在 BottomTabNavigator 上实现自定义标题
- r - 在 R 中使用爪子——列出 AWS 工作区