使用 Web3 向 Uniswap 池添加流动性

时间:2021-02-24 14:50:23

标签: web3js

我正在尝试使用 Web3 为 Ropsten 网络上的 Uniswap 添加流动性。

我的 JavaScript 代码如下:

  (async () => {
  console.log("account: ", this.state.account);
  const deployedContract = await new web3.eth.Contract(
    UniswapRouter02Contract.abi,
    "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
  );
  console.log(web3.currentProvider);
  console.log("pair address ", this.state.pairAddress);
  console.log(this.state);
  const liq = await deployedContract.methods
    .addLiquidity(
      this.state.firstAddress,
      this.state.secondAddress,
      1000,
      1000,
      0,
      0,
      this.state.pairAddress,
      200
    )
    .send(
      {
        from: this.state.account,
        gas: "2000000"
      },
      function(error, transactionHash) {}
    )
    .on("error", error => {
      console.log("my error", error.message);
    });

  //console.log("Events", pairCreated.events);
})();

我的错误:

Transaction has been reverted by the EVM: { "blockHash": "0xc4bcbfe7c4e6045d20b466f7eab2a7af1693cb3e11be7a197722855876554eaa", "blockNumber": 9707061, "contractAddress": null,
"cumulativeGasUsed": 4110545, "from": "0xe3a6752cf416bd9fb766b046782a21b8722bcc3c", "gasUsed": 23341,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": false, "to": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d", "transactionHash": "0xf23421d4a6cba30515e01e288893e8ecda482fccc1e3b969966187855298120c", "transactionIndex": 8, "events": {} }

我还有一个问题:我必须在 Uniswap addLiquidity 函数中输入参数“to”的地址和截止日期是什么?

功能:

function addLiquidity(
   address tokenA,
   address tokenB,
   uint amountADesired,
   uint amountBDesired,
   uint amountAMin,
   uint amountBMin,
   address to,
   uint deadline ) external returns (uint amountA, uint amountB, uint liquidity);

0 个答案:

没有答案