3

I'm having problems retrieving some data metrics using the Uniswap JS SDK. When I try to query getInputAmount it returns this error:

(node:88) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'equals' of undefined
    at Pair.involvesToken (/mnt/c/Users/Joe/node_modules/@uniswap/sdk/dist/sdk.cjs.development.js:790:18)
    at Pair.getInputAmount (/mnt/c/Users/Joe/node_modules/@uniswap/sdk/dist/sdk.cjs.development.js:837:11)
    at init (/mnt/c/Users/Joe/Desktop/JStest/myScripts/TEST.js:8:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:88) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or 
by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:88) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This is the JS code I'm running:

const { ChainId, Token, WETH, Fetcher } = require('@uniswap/sdk')  

const DAI = new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18)  

const init = async () => {     
    const pair = await Fetcher.fetchPairData(DAI, WETH[DAI.chainId])
    const amount = await pair.getInputAmount('1000000000000000000');
    console.log(amount);
}  

init();

I would really appreciate your guidance on how to proceed!

0

Parameter of getInputAmount or getOutputAmount is value of type TokenAmount (not string as you provided).

import { TokenAmount } from '@uniswap/sdk'
...
const daiAmount = new TokenAmount(DAI /* or another token */, '1000000000000000000')
const inputAmount = await pair.getInputAmount(daiAmount);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.