Giter Site home page Giter Site logo

Comments (10)

Oguntoye avatar Oguntoye commented on August 23, 2024 26

@james-stevens and anyone who is having this issues

From Web3.js 4.x

You should do this
const { Web3 } = require('web3');

Instead of doing this
const Web3 = require('web3');

from ethereum-bridge.

james-stevens avatar james-stevens commented on August 23, 2024 2
#! /usr/bin/node

const myWeb3 = require("web3");
const web3 = new myWeb3("https://eth-mainnet.g.alchemy.com/v2/**************************");

web3.eth.ens.getContenthash("james.eth").then((result) => { console.log(result); });

gets....

const web3 = new myWeb3("https://eth-mainnet.g.alchemy.com/v2/I1iLOFKvcQ5NEt7GnYfmQDwXpYipWPaw");
             ^

TypeError: myWeb3 is not a constructor
    at Object.<anonymous> (/root/python/web3/web3.js:4:14)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

worked fine until I upgraded node from v16 to v18

Tried updating web3, tried removing it & reinstalling it - no luck

from ethereum-bridge.

james-stevens avatar james-stevens commented on August 23, 2024 1

thanks @Oguntoye, I went with converting to module syntax

import { Web3 } from 'web3';
const web3 = new Web3("https://eth-mainnet.g.alchemy.com/v2/*****************");

I was just disappointed that code that had worked in node v16 then failed just by upgrading to node v18 - and ALL the tutorials I found online used to older syntax, that now doesn't work.

Getting anything working in web3 is hard enough - to then have it killed by an update was a killer.

from ethereum-bridge.

marcogiglio avatar marcogiglio commented on August 23, 2024

Hi @R-a-x , have you run npm install before?

from ethereum-bridge.

rahulbansal16 avatar rahulbansal16 commented on August 23, 2024

@marcogiglio its hard to say, is there any way I can confirm that

from ethereum-bridge.

marcogiglio avatar marcogiglio commented on August 23, 2024

Probably not if you have this error. Just try to run it and see if it works?

from ethereum-bridge.

mandritac avatar mandritac commented on August 23, 2024

If you have executed npm install then a folder called "node_modules" should get created in your ethereum bridge extracted folder.

from ethereum-bridge.

Medha08 avatar Medha08 commented on August 23, 2024

I ran into the same issue,solved it by deleting package-lock.json, node_modules and doing npm install again. See if it works for you

from ethereum-bridge.

D-Nice avatar D-Nice commented on August 23, 2024

stale issue

from ethereum-bridge.

AfnanQureshi1 avatar AfnanQureshi1 commented on August 23, 2024

getting same error! anyone resolved it?

from ethereum-bridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.