我正试着得到100块钱我能收到的WETH的数量:
uniswapController.sol
contract UniswapController {
address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
IUniswapV2Router02 public uniswapRouter;
constructor() public {
uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS);
}
function getAmountsOut(uint fundingamount, address[] memory path) public view returns (uint[] memory) {
return uniswapRouter.getAmountsOut(fundingamount, path);
}js客户端代码:
dai.address = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
ethereum.address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
let amounts = await uniswapController.getAmountsOut(100, [dai.address, ethereum.address]);
let daioutput = amounts[0].toNumber();
let ethereumoutput = amounts[1].toNumber();
console.log("Dai output:", daioutput); // returns 100
console.log("ethereum output:", ethereumoutput); // returns 0我如何返回我可以得到的100代,而不是仅仅0的部分WETH?
发布于 2021-06-18 01:44:43
你应该把100转换成魏。
如果您使用web3.js,您可以这样做
web3.utils.toWei(100);https://ethereum.stackexchange.com/questions/102069
复制相似问题