【问题标题】:uniswap swapExactTokensForTokens is making the transaction but not swapping between the coinsuniswap swapExactTokensForTokens 正在进行交易,但没有在硬币之间交换
【发布时间】:2021-11-22 17:05:49
【问题描述】:

我正在尝试使用以太币在 2 个硬币之间实现基本交换,但没有成功。 我成功了: https://ropsten.etherscan.io/tx/0x9d09a50143f8e1ec1c72b17007d664b96e931a96cd1f08f5a78b94a9b834e691

但是 结果是我可以看到ETH的数量减少了,但是我的GCOIN和FLOG币还是一样,我错过了什么?

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);

【问题讨论】:

    标签: javascript blockchain swap


    【解决方案1】:

    我想我在这里看到了一个问题。

    乍一看,在我看来,您正在将令牌发送到 uniswapRouterAddress。我的理解是swapExactTokensForTokens中的第四个参数应该是你想要接收交换代币的地址。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-22
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 2022-11-04
      • 2022-07-29
      • 1970-01-01
      相关资源
      最近更新 更多