我不明白为什么当我试图部署我的合同时,它说气体估计错误。使用ganache-cli -f <INFURA_ID>尝试部署和执行以下代码:
pragma solidity ^0.7.0;
import 'IERC20.sol';
import 'IUniswap.sol';
contract Uniswap_Swap {
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address daiAddress = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
IUniswap public uniswapRouter;
constructor() {
uniswapRouter = IUniswap(UNISWAP_ROUTER_ADDRESS);
}
function convertEthToDai(uint daiAmount) public payable {
uint deadline = block.timestamp + 15;
uniswapRouter.swapExactETHForTokens{ value: msg.value }(daiAmount, getPathForETHtoDAI(), address(this), deadline);
(bool success,) = msg.sender.call{ value: address(this).balance }("");
require(success, "refund failed");
}
function getPathForETHtoDAI() private view returns (address[] memory) {
address[] memory path = new address[](2);
path[0] = uniswapRouter.WETH();
path[1] = daiAddress;
return path;
}
receive() payable external {}
}任何帮助都非常感谢。
编辑:迁移文件
const UniswapExample = artifacts.require("UniswapExample");
module.exports = function (deployer) {
deployer.deploy(UniswapExample);
};用混合和直接通过终端的方法尝试。甚至编写了一个python代码来调用。我得到的最接近的是蟒蛇和Excessive_Input_Error。虽然我认为不需要增加任何流动性,因为主干网叉。
发布于 2021-03-17 08:45:23
我想我也遇到了同样的问题,尽管我用硬帽子在主干网上分叉。当使用web3py时,这个设置是正确的:
preparedTx = myContract.functions.myFun(*params).buildTransaction({
'chainId': 31337,
'gas': 700000,
'gasPrice': web3.toWei('1', 'gwei'),
'nonce': nonce,
})注意,gasPrice设置较低,chainId切换到本地RPC,这在hardhat/ganache中有文档记录。
https://ethereum.stackexchange.com/questions/92164
复制相似问题