Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Token.fetchData is not a function #53

Open
hlairboltons opened this issue May 10, 2021 · 12 comments
Open

TypeError: Token.fetchData is not a function #53

hlairboltons opened this issue May 10, 2021 · 12 comments

Comments

@hlairboltons
Copy link

hlairboltons commented May 10, 2021

Hello I am following the pro course on profitable-arbitrage, 15 Poll Uniswap Prices. When i run run-arbitrage.js I get the following error. What does this mean and how I proceed? Thanks

Blair@DESKTOP-L81FL5C MINGW64 ~/profitable-flashloans
$ node run-arbitrage.js
C:\Users\Blair\profitable-flashloans\run-arbitrage.js:24
Token.fetchData(
^
TypeError: Token.fetchData is not a function
at C:\Users\Blair\profitable-flashloans\run-arbitrage.js:24:19
at Array.map ()
at init (C:\Users\Blair\profitable-flashloans\run-arbitrage.js:23:55)
at Object. (C:\Users\Blair\profitable-flashloans\run-arbitrage.js
:78:1)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_ma
in:76:12)
at node:internal/main/run_main_module:17:47

@antonmn
Copy link

antonmn commented May 11, 2021

Having the same problem ....... any solution?

@cherylkw
Copy link

cherylkw commented Jun 10, 2021

I think uniswap SDK v2 has new features and no longer supports fetchdata method. So try to use Fetcher.fetchTokenData and Fetcher.fetchPairData.

@RolandoDrRobot
Copy link

@cherylkw you da man! It worked perfectly

@supergav1967
Copy link

Hi all....I am having the same issue as detailed in the thread above! When I install UniSwap SDK I am installing v3? Is there anyway to install a specific SDK version, and also it would appear that SDK v2 allows Fetcher.fetchTokenData and Fetcher.fetchPairData and appeared to work...if so what was the code amendment please?

@supergav1967
Copy link

I think uniswap SDK v2 has new features and no longer supports fetchdata method. So try to use Fetcher.fetchTokenData and Fetcher.fetchPairData.

@cherylkw you da man! It worked perfectly

Hi there. What was the code amendments you made please>

@NumberXXIV
Copy link

from Batman, in another thread
So you have installed uniswap/sdk @3.0.3 The code requires uniswap/sdk @2.0.5
You can install specific ersions like this:
Npm install @uniswap/sdk@2.0.5

@jt311
Copy link

jt311 commented Sep 15, 2021

@NumberXXIV thanks so much this worked

@scottbailey1234
Copy link

To elaborate a bit for those in the tutorial who may not be aware of every aspect of object oriented coding structures. If you installed using @uniswap/sdk, and did not indicate a version as of 10/22/2021, you would have installed version 3.0.3.

In this case, in the const used to import values from uniswap (at the top of the code), you'll need to replace the "Token" and "Pair" statements with a single "Fetcher" statement. Then, within your methods in the code, replace "Token.fetchData" and "Pair.fetchData" with "Fetcher.fetchTokenData" and "Fetcher.fetchPairData"

It should look like this,
const { ChainId, TokenAmount, Fetcher } = require('@uniswap/sdk'); //import field values from uniswap

Then, within your method,

const init = async () => { //Apply WETH to process - In Uniswap, weth is used to trade ETH. ETH is sent to a weth token and the weth token is used to represent ETH during the trade.
const [dai, weth] = await Promise.all(
[addresses.tokens.dai, addresses.tokens.weth].map(tokenAddress => (
Fetcher.fetchTokenData(
ChainId.MAINNET,
tokenAddress,
)
)));
const daiWeth = await Fetcher.fetchPairData(
dai,
weth
);

To @wcDogg's point... EatTheBlocks course designers need to modify these details in the instructions or provide additional training on how we can manage version changes for the many different npm installs that are required for the build. It's an expensive course and it's no surprise that people will be frustrated on this one.

@blockpartines
Copy link

require('dotenv').config()
const Web3 = require('web3');
const { ChainId, TokenAmount, Fetcher } = require('@uniswap/sdk');
const abis = require('./abis');
const { mainnet: addresses } = require('./addresses');

const web3 = new Web3(
new Web3.providers.WebsocketProvider('process.env.INFURA_URL')
);

const kyber = new web3.eth.Contract(
abis.kyber.kyberNetworkProxy,
addresses.kyber.kyberNetworkProxy
);

const AMOUNT_ETH = 100;
const RECENT_ETH_PRICE = 230;
const AMOUNT_ETH_WEI = web3.utils.toWei(AMOUNT_ETH.toString());
const AMOUNT_DAI_WEI = web3.utils.toWei((AMOUNT_ETH * RECENT_ETH_PRICE).toString());

const init = async () => {
const [dai, weth] = await Promise.all(
[addresses.tokens.dai, addresses.tokens.weth].map(tokenAddress => (
Fetcher.fetchTokenData(
ChainId.MAINNET,
tokenAddress,
)
)));
daiWeth = await Fetcher.fetchPairData(
dai,
weth,
);

web3.eth.subscribe('newBlockHeaders')
.on('data', async block => {
console.log(New block received. Block # ${block.number});

  const kyberResults = await Promise.all([
      kyber
        .methods
        .getExpectedRate(
          addresses.tokens.dai, 
          '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 
          AMOUNT_DAI_WEI
        ) 
        .call(),
      kyber
        .methods
        .getExpectedRate(
          '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 
          addresses.tokens.dai, 
          AMOUNT_ETH_WEI
        ) 
        .call()
  ]);
  const kyberRates = {
    buy: parseFloat(1 / (kyberResults[0].expectedRate / (10 ** 18))),
    sell: parseFloat(kyberResults[1].expectedRate / (10 ** 18))
  };
  console.log('Kyber ETH/DAI');
  console.log(kyberRates);

  const uniswapResults = await Promise.all([
    daiWeth.getOutputAmount(new TokenAmount(dai, AMOUNT_DAI_WEI)),
    daiWeth.getOutputAmount(new TokenAmount(weth, AMOUNT_ETH_WEI))
  ]);
  const uniswapRates = {
    buy: parseFloat( AMOUNT_DAI_WEI / (uniswapResults[0][0].toExact() * 10 ** 18)),
    sell: parseFloat(uniswapResults[1][0].toExact() / AMOUNT_ETH),
  };
  console.log('Uniswap ETH/DAI');
  console.log(uniswapRates);
})
.on('error', error => {
  console.log(error);
});

}
init();

@JvBug
Copy link

JvBug commented May 6, 2022

from Batman, in another thread So you have installed uniswap/sdk @3.0.3 The code requires uniswap/sdk @2.0.5 You can install specific ersions like this: Npm install @uniswap/sdk@2.0.5

I was having the same issue and this solved it so easily. Thank you!!

@CyHunterX
Copy link

To elaborate a bit for those in the tutorial who may not be aware of every aspect of object oriented coding structures. If you installed using @uniswap/sdk, and did not indicate a version as of 10/22/2021, you would have installed version 3.0.3.

In this case, in the const used to import values from uniswap (at the top of the code), you'll need to replace the "Token" and "Pair" statements with a single "Fetcher" statement. Then, within your methods in the code, replace "Token.fetchData" and "Pair.fetchData" with "Fetcher.fetchTokenData" and "Fetcher.fetchPairData"

It should look like this, const { ChainId, TokenAmount, Fetcher } = require('@uniswap/sdk'); //import field values from uniswap

Then, within your method,

const init = async () => { //Apply WETH to process - In Uniswap, weth is used to trade ETH. ETH is sent to a weth token and the weth token is used to represent ETH during the trade. const [dai, weth] = await Promise.all( [addresses.tokens.dai, addresses.tokens.weth].map(tokenAddress => ( Fetcher.fetchTokenData( ChainId.MAINNET, tokenAddress, ) ))); const daiWeth = await Fetcher.fetchPairData( dai, weth );

To @wcDogg's point... EatTheBlocks course designers need to modify these details in the instructions or provide additional training on how we can manage version changes for the many different npm installs that are required for the build. It's an expensive course and it's no surprise that people will be frustrated on this one.

Super helpful you make my day :).

@miklasz
Copy link

miklasz commented Oct 6, 2022

i manage to make it work:
npm uninstall @uniswap/sdk

and then

npm install @uniswap/sdk@2.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests