Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Uniswap swapExactTokensForTokens is making the transaction but not swapping between the coins

I'm trying to implement a basic swap between 2 coins, using ethers, but without success.

I get success: https://ropsten.etherscan.io/tx/0x9d09a50143f8e1ec1c72b17007d664b96e931a96cd1f08f5a78b94a9b834e691

but the result is that I can see that the amount of the ETH is reduced, but my GCOIN and FLOG coin is still the same, what am I missing?

const walletAddress = "0xD5768aa815D590494277f558Ee5cbeC5FAF1501C";
const GCOINErc20Address = "0x0eb8c372066EbB30B256E8F8707EaA81cB68225D";
const FLOGErc20Address = "0x5a44be26dd414ebfc4beee5c40af5cc5272a62c7";
const ropstenUniswap = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'
const uniswapRouterAbi = [
    "function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)",
];

async function buyListedTokenWithEth(
    amountEthFloat,
    uniswapRouterAddress,
    provider
) {
    console.log('start')
    let privateKey = "private_key";
    let provider2 = ethers.providers.getDefaultProvider({name: 'ropsten', chainId: 3});
    console.log(provider2)
    let wallet = new ethers.Wallet(privateKey, provider2);
    const signer = wallet.connect(provider2); 
    const exchangeContract = new ethers.Contract(
        uniswapRouterAddress,
        uniswapRouterAbi,
        signer
    );
    const ethAmount = ethers.utils.parseUnits(amountEthFloat);
    console.log(exchangeContract)
    const tx = await exchangeContract.swapExactTokensForTokens(
        ethAmount,
        1,
        [FLOGErc20Address, GCOINErc20Address],
        uniswapRouterAddress,
        Date.now() + 1000 * 60 * 10, //10 minutes,
        {
            'gasLimit': 300000,
            'gasPrice': ethers.utils.parseUnits('500', 'gwei'),
        });
    console.log("https://ropsten.etherscan.io/tx/" + tx.hash);
}

buyListedTokenWithEth('1', walletAddress, provider);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think I see an issue here.

At a quick glance, it looks to me like you're sending the tokens to uniswapRouterAddress. My understanding is that the 4th argument in swapExactTokensForTokens should be the address that you want to receive the swapped tokens.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda