uniswap v2router 调用addLiquidity总是resvert

/**
 * 连接测试链
 */

let Web3 = require('web3');
// var web3 = new Web3(Web3.givenProvider || "ws://localhost:8545");

// 连接到 ropsten 测试节点
var web3 = new Web3();
web3.setProvider(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/6228221f6f894b5684e1b91bba538902"))

let fs = require('fs')

let source = fs.readFileSync('/Users/zhangchaoyin/node/ethereum/truffle_study/study_02/uniswap-periphery/build/contracts/UniswapV2Router02.json')

let {
  abi
} = JSON.parse(source)

let liamTokenAddress = '0x39A8A93ab5fEbE3c9fb152A10025b8f3Ea5864fa'
let hangSonTokenAddress = '0x526981A02308cAa5f77a97e2fD314085b64B2d30'
let from = '0xb8C3a29963f5EbB45c95873E8C448cEF5148A38f'
let privKey =
  "f3845b667c850652be0aebf73048ea58a887df984c7e1e4f0949268cd733b9a2";
let uniswapV2Router02Address = '0xF404739DC4b65F02b0544E5CBe0790bcB9056f28'

let {
  sendSignedTransaction
} = require('../utils/sendSignedTransaction')

let addLiquidity = async () => {
  let amountADesired = 10000000000
  let amountBDesired = 1000000000
  let amountAMin = 10000
  let amountBMin = 1000
  let block = await web3.eth.getBlock("latest");
  let deadline = block.timestamp + 300;
  console.log(deadline);
  let uniswapV2Router02Storage = new web3.eth.Contract(abi, uniswapV2Router02Address)
  let uniswapV2Router02StorageTx = await uniswapV2Router02Storage.methods.addLiquidity(liamTokenAddress, hangSonTokenAddress, amountADesired, amountBDesired, amountAMin, amountBMin, from, deadline)
  await sendSignedTransaction(uniswapV2Router02StorageTx, from, uniswapV2Router02Address, privKey)

};

addLiquidity();

是否是调用前还需进行别的操作,当合约代码执行到createPair 总是失败

请先 登录 后评论

2 个回答

崔棉大师
请先 登录 后评论
Alan
请先 登录 后评论
  • 2 关注
  • 0 收藏,4711 浏览
  • liam 提出于 2021-03-24 17:19