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

Is there a way to get this to work? Cascading errors: web3.eth.Contract is not a constructor // TypeError: Cannot read properties of undefined (reading 'toWei') #40

Open
noob1ing opened this issue Jun 9, 2022 · 4 comments

Comments

@noob1ing
Copy link

noob1ing commented Jun 9, 2022

When I try to npm run start this code I get this error:


TypeError: web3.eth.Contract is not a constructor
at Object. (C:\Users\John\demos\DAAP university\TAKE 2\price-bot\index.js:31:27)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47


If I change the constructor format from
const uniswapFactoryContract = new web3.eth.Contract(UNISWAP_FACTORY_ABI, UNISWAP_FACTORY_ADDRESS)
to
const uniswapFactoryContract = web3.eth.contract(UNISWAP_FACTORY_ABI, UNISWAP_FACTORY_ADDRESS)

then I get this error
TypeError: Cannot read properties of undefined (reading 'toWei')
at monitorPrice (C:\Users\John\demos\DAAP university\TAKE 2\price-bot\index.js:73:31)
at Timeout._onTimeout (C:\Users\John\demos\DAAP university\TAKE 2\price-bot\index.js:112:48)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)

is this tutorial dead or is there a way to make this code run?

@CibolinCode
Copy link

CibolinCode commented Jun 9, 2022 via email

@noob1ing
Copy link
Author

noob1ing commented Jun 9, 2022

Thanks for your help

@OpeOginni
Copy link

For this Error: TypeError: Cannot read properties of undefined (reading 'toWei')

Change all occurrences of web3.utils.toWei To web3.toWei

@BernardTeske
Copy link

I got it to work with this: https://web3js.readthedocs.io/en/v1.8.2/web3-eth-contract.html#eth-contract

  1. npm install web3-eth-contract
  2. add Contract.setProvider(process.env.RPC_URL); after Line const web3 = new Web3(process.env.RPC_URL)
  3. change every new web3.eth.Contract( to new Contract(

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

4 participants