Comments (12)
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.
from eattheblocks.
I think uniswap SDK v2 has new features and no longer supports fetchdata method. So try to use Fetcher.fetchTokenData and Fetcher.fetchPairData.
from eattheblocks.
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();
from eattheblocks.
Having the same problem ....... any solution?
from eattheblocks.
@cherylkw you da man! It worked perfectly
from eattheblocks.
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?
from eattheblocks.
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>
from eattheblocks.
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/[email protected]
from eattheblocks.
@NumberXXIV thanks so much this worked
from eattheblocks.
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/[email protected]
I was having the same issue and this solved it so easily. Thank you!!
from eattheblocks.
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 :).
from eattheblocks.
i manage to make it work:
npm uninstall @uniswap/sdk
and then
npm install @uniswap/[email protected]
from eattheblocks.
Related Issues (20)
- Audit found that the transferFrom function never deducts the allowance value HOT 1
- Error recived Lesson 12 flash loans
- How can i deploy the pancakeswap sniper bot
- LESSON 28: DEPLOY FLASHLOAN SMART CONTRACT
- How to automate a function in a smart contract? HOT 2
- Money Legos- Source not found?
- 330-uniswap-trading How works on real chain?
- Error: Transaction has been reverted by the EVM - 298-arbitrage-uniswap-sushiswap HOT 1
- error when tried to connect to infura blockchain LESSON 12 HOT 1
- [day22-ICO] withdraw() never possible, because `released` never set to true.
- Truflle migrate stuck
- Warning when trying to compile Equalizer Finance loan using Remix
- Bug
- Adding a license, contributions and a code of conduct for the repo
- Create issue templates for the different types of issues
- TypeError: Cannot read property 'address' of undefined at init
- ArgumentsRequired: binance amount of BTC/USDT must be greater than minimum amount precision of 5
- 第12课。连接不到infura。报错1006
- ETH Amount in Wallet
- New Developers - List Your Blockchain dApps for Sale on Pinky Finance HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eattheblocks.