CRYPTO NEWS

ethers.js swapExactTokensForTokens not happening (no errors)

Been stuck on swapping tokens using ethers js, here’s the code I’m using:

const https_provider = new ethers.providers.JsonRpcProvider(https_provider_addres) const wallet = new ethers.Wallet.fromMnemonic(mnemonic) const account = wallet.connect(provider) const https_account = wallet.connect(https_provider)  const erc20_ABI =     [         {             "constant": true,             "inputs": [],             "name": "name",             "outputs": [                 {                     "name": "",                     "type": "string"                 }             ],             "payable": false,             "stateMutability": "view",             "type": "function"         },         {             "constant": false,             "inputs": [                 {                     "name": "_spender",                     "type": "address"                 },                 {                     "name": "_value",                     "type": "uint256"                 }             ],             "name": "approve",             "outputs": [                 {                     "name": "",                     "type": "bool"                 }             ],             "payable": false,             "stateMutability": "nonpayable",             "type": "function"         },         {             "constant": true,             "inputs": [],             "name": "totalSupply",             "outputs": [                 {                     "name": "",                     "type": "uint256"                 }             ],             "payable": false,             "stateMutability": "view",             "type": "function"         },         {             "constant": false,             "inputs": [                 {                     "name": "_from",                     "type": "address"                 },                 {                     "name": "_to",                     "type": "address"                 },                 {                     "name": "_value",                     "type": "uint256"                 }             ],             "name": "transferFrom",             "outputs": [                 {                     "name": "",                     "type": "bool"                 }             ],             "payable": false,             "stateMutability": "nonpayable",             "type": "function"         },         {             "constant": true,             "inputs": [],             "name": "decimals",             "outputs": [                 {                     "name": "",                     "type": "uint8"                 }             ],             "payable": false,             "stateMutability": "view",             "type": "function"         },         {             "constant": true,             "inputs": [                 {                     "name": "_owner",                     "type": "address"                 }             ],             "name": "balanceOf",             "outputs": [                 {                     "name": "balance",                     "type": "uint256"                 }             ],             "payable": false,             "stateMutability": "view",             "type": "function"         },         {             "constant": true,             "inputs": [],             "name": "symbol",             "outputs": [                 {                     "name": "",                     "type": "string"                 }             ],             "payable": false,             "stateMutability": "view",             "type": "function"         },         {             "constant": false,             "inputs": [                 {                     "name": "_to",                     "type": "address"                 },                 {                     "name": "_value",                     "type": "uint256"                 }             ],             "name": "transfer",             "outputs": [                 {                     "name": "",                     "type": "bool"                 }             ],             "payable": false,             "stateMutability": "nonpayable",             "type": "function"         },         {             "constant": true,             "inputs": [                 {                     "name": "_owner",                     "type": "address"                 },                 {                     "name": "_spender",                     "type": "address"                 }             ],             "name": "allowance",             "outputs": [                 {                     "name": "",                     "type": "uint256"                 }             ],             "payable": false,             "stateMutability": "view",             "type": "function"         },         {             "payable": true,             "stateMutability": "payable",             "type": "fallback"         },         {             "anonymous": false,             "inputs": [                 {                     "indexed": true,                     "name": "owner",                     "type": "address"                 },                 {                     "indexed": true,                     "name": "spender",                     "type": "address"                 },                 {                     "indexed": false,                     "name": "value",                     "type": "uint256"                 }             ],             "name": "Approval",             "type": "event"         },         {             "anonymous": false,             "inputs": [                 {                     "indexed": true,                     "name": "from",                     "type": "address"                 },                 {                     "indexed": true,                     "name": "to",                     "type": "address"                 },                 {                     "indexed": false,                     "name": "value",                     "type": "uint256"                 }             ],             "name": "Transfer",             "type": "event"         }     ]  const addresses = {     WAVAX: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",     router: "0x60aE616a2155Ee3d9A68541Ba4544862310933d4",     factory: "0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10", }  const router = new ethers.Contract(     addresses.router,     [         'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',         'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',         'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',     ],     account )  const USDC_address = '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E'  const STG_address = "0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590" const STG_contract = new ethers.Contract(     STG_address,     erc20_ABI,     https_account )  const swap = async () => {      console.log('swap starting')      const amountIn = "22146823544065952776"      const amounts = await router.getAmountsOut(amountIn, [         STG_address,         USDC_address     ])      const amountOutMin = amounts[1].sub(amounts[1].div(12))     console.log('amountOutMin: ' + amountOutMin)      const tx = await router.swapExactTokensForTokens(         amountIn,         amountOutMin,         [STG_address, USDC_address],         https_account.address,         Math.floor(Date.now() / 1000) + 60 * 6, // 6 mins from current         {             gasLimit: 5000009999         }     )      console.log('Swap done!')     const receipt = await tx.wait()     console.log('Transaction receipt' + receipt) }  const init = async () => {     console.log('before contract approve')      //     let receipt = STG_contract.connect(https_account).approve("0x60aE616a2155Ee3d9A68541Ba4544862310933d4", ethers.utils.parseUnits('1000.0', 18)).then((results) => {         console.log(results)         swap()     })      console.log(receipt)     console.log('await contract approve happened') }  init() 

The approve works fine, I get the expected console output, tx hash (can verify on snowtrace etc)

Problem is with the actual swap, I get the amounts out, but after when attempting swapExactTokensForTokens basically nothing happens – it just keeps hanging forever, no errors, nothing

Any ideas?

NomicLabsHardhatPluginError: Failed to send contract verification request

Im stuck in this wierd error. so the thing is when I first tried to deploy the contract on goerli it deployed and verified correctly on etherscan. but after that when I tried to run my staging test it gave me the error of timing out of 200000 and as per your suggestions I increased::Listen

Im stuck in this wierd error.

enter image description here

so the thing is when I first tried to deploy the contract on goerli it deployed and verified correctly on etherscan. but after that when I tried to run my staging test it gave me the error of timing out of 200000 and as per your suggestions I increased the timeout to 500000, but yet it didn’t work (I even increased the timeout to 900000 but it didn’t work as well). On the next day when I tried to run this command hh test –network Goerli it started giving me this error(which was not coming on the previous day)

     ConnectTimeoutError: Connect Timeout Error 

I then tried to deploy the contract again and that’s when I started getting that error mentioned in the screenshot above. it is sometimes giving this error as well .

NomicLabsHardhatPluginError: Failed to obtain list of solc versions. Reason: Connect Timeout Error 

here is my github repo link of this project.

https://github.com/OmarWaqar123/hardhat_raffle_Iscausingerror 

and as I mentioned above the contract is verified on etherscan so here is my contract address;

0x39d8Ce13CC461B82b82Ca1DD9C484f544b78C1cd 

also, as I mentioned above it’s a bit weird problem because it’s giving different errors while running the same command for testing after some time or a day. like right now after another day it’s giving me this error

     Error: Timeout of 500000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/omar/hh-Omar1/hardhat-smartcontract-lottery-fcc/test/unit/staging/Raffle.staging.test.js)  

and when trying to verify it’s giving this error.

     Error: missing revert data in call exception; Transaction reverted without a reason string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (data="0x", transaction={"from":"0x9e250e1d6a99B734CB2d4F608014389b420791EA","to":"0x39d8Ce13CC461B82b82Ca1DD9C484f544b78C1cd","data":"0x91ad27b4","accessList":null}, error={"name":"ConnectTimeoutError","code":"UND_ERR_CONNECT_TIMEOUT","message":"Connect Timeout Error"}, code=CALL_EXCEPTION, version=providers/5.7.0) 

ethers.js swapExactTokensForTokens not happening (no errors)

Shopping cart
There are no products in the cart!
Continue shopping
0