var Web3 = require("Web3");
I have downloaded the web3 modules using npm but the above statement in my HTML code is still showing error
try:
var Web3 = require('web3');
The package name starts with a lower case w.
@michaelsbradleyjr still the same
@narayanshivansh49 are you using some front-end build tooling like webpack? Do you have a repository I can look at?
Using of a bundler is required if you install it from NPM. The minified file can be found here on GitHub in the dist folder.
@nivida The minified file in the dist folder still contains the call to require(), so it can't be used in a browser (as of version 1.2.4).
What is the best way for me to generate a minified version of 1.2.4 that works?
@myq I tried uploading web3.min.js from the dist/ folder on the 1.x branch to codesandbox and then making use of it in a sandbox with:
<script src="https://uploads.codesandbox.io/uploads/user/68052bd8-43d7-466a-af1e-bb0ab2bd3a40/F6-W-web3.min.js"></script>
It seems to work fine, i.e. in the browser console I can see there is indeed a global variable named Web3 and web3 = new Web3() works.
@cgewecke fixed this in #3261, so cloning the repo and building the minified version should work.
I'm not sure if the minified file in dist/ should be updated before a new release though. Should it track the latest released version? I normally don't push autogenerated files, so I'm not sure what's common in this case.
sir , i'm getting same problem
this is my code -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
var Web3 = require('web3');
var web3 = new Web3('http://localhost:8545');
var conrtract_abi = [{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "My_Message",
"type": "string"
}
],
"name": "put",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getvalue",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
var contact_address = '0x62Fbd0989fbc743dDF11DA5b18e34d9Ffc59a199';
var simple_contract = new Web3.eth.Contract(conrtract_abi, contact_address);
console.log(simple_contract)
Web3.eth.getAccounts().then(console.log);