我在使用 uniswapV2 路由器交换 Solidity 时遇到了一些问题。那是我的测试脚本
it("swap", async function () {
let rec = [receivers1, receivers2, receivers3];
const somma = await mecenate.calculate(rec, level);
const toBuy = new BigNumber.from(somma);
const amountInMin = await mecenate.getAmountsIn(toBuy);
const ownerBalanceBefore = await provider.getBalance(owner.address);
console.log(toBuy, amountInMin[0], owner.address);
await mecenate.swapUSTtoETH(toBuy, amountInMin[0], owner.address);
const ownerBalanceAfter = await provider.getBalance(owner.address);
expect(ownerBalanceAfter).to.equal(ownerBalanceBefore);
});
这是我的合约功能
function swapUSTtoETH(uint256 _amountOut, uint256 _amountInMax, address _to) external
isOwner
{
uint toApprove = _amountInMax *5;
IERC20(USTaddress).transferFrom(msg.sender, address(this), _amountInMax);
IERC20(USTaddress).approve(routerV2, toApprove);
uni.swapTokensForExactETH(
_amountOut,
_amountInMax,
getPathForUSTtoETH(),
_to,
block.timestamp
);
}
给我这个错误:
ProviderError: VM Exception while processing transaction: revert Failed to send Ether
谢谢