You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started the local network from the fork mainnet through the hardhat node script, and then continued to execute the hardhat test --network localhost script to perform swap testing on the local network. When I executed the line simpleSwap.swapExactInputSingle, I I encountered the error VM Exception while processing transaction: reverted with reason string 'STF'. Please tell me how I should handle and solve this error.
importhre,{ethers}from"hardhat";constWETH_ADDRESS="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";constDAI_ADDRESS="0x6B175474E89094C44Da98b954EedeAC495271d0F";constDAI_DECIMALS=18;constSwapRouterAddress="0xE592427A0AEce92De3Edee1F18E0157C05861564";constercAbi=[// Read-Only Functions"function balanceOf(address owner) view returns (uint256)",// Authenticated Functions"function transfer(address to, uint amount) returns (bool)","function deposit() public payable","function approve(address spender, uint256 amount) returns (bool)",];describe("SimpleSwap",()=>{it("Should provide a caller with more UST than they started with after a swap",async()=>{// 合约部署constsimpleSwapFactory=awaitethers.getContractFactory("SimpleSwap");constsimpleSwap=awaitsimpleSwapFactory.deploy(SwapRouterAddress);awaitsimpleSwap.waitForDeployment();constsigners=awaitethers.getSigners();// 包装一部分的 ETH 到 WETHconstWETH=newethers.Contract(WETH_ADDRESS,ercAbi,signers[0]);constdeposit=awaitWETH.deposit({value: ethers.parseEther("10")});awaitdeposit.wait();// 检查 DAI 余额constDAI=newethers.Contract(DAI_ADDRESS,ercAbi,signers[0]);constexpandedDAIBalanceBefore=awaitDAI.balanceOf(signers[0].address);constDAIBalanceBefore=Number(ethers.formatUnits(expandedDAIBalanceBefore,DAI_DECIMALS));console.log(awaitsimpleSwap.getAddress(),simpleSwap.target);// 审批 WETH 转移到 swap 合约awaitWETH.approve(awaitsimpleSwap.getAddress(),ethers.parseEther("1"));// 执行 swapconstamountIn=ethers.parseEther("0.1");console.log(amountIn);constswap=awaitsimpleSwap.swapExactInputSingle(amountIn,{gasLimit: 300000,});swap.wait();// const expandedDAIBalanceAfter = await DAI.balanceOf(signers[0].address);// const DAIBalanceAfter = Number(// hre.ethers.formatUnits(expandedDAIBalanceAfter, DAI_DECIMALS)// );// console.log(DAIBalanceBefore, DAIBalanceAfter);});});
The text was updated successfully, but these errors were encountered:
I started the local network from the fork mainnet through the
hardhat node
script, and then continued to execute thehardhat test --network localhost
script to perform swap testing on the local network. When I executed the linesimpleSwap.swapExactInputSingle
, I I encountered the errorVM Exception while processing transaction: reverted with reason string 'STF'
. Please tell me how I should handle and solve this error.Error stack
hardhat.config.ts
My swap contract
Test code
The text was updated successfully, but these errors were encountered: