I have geth running on localhost:

geth.exe --testnet --fast --cache 1024 --ipcpath \\.\pipe\geth.ipc --rpccorsdomain * --rpcport 8545 --rpc

If I do the following:

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
var abi = ...

This gives me an error: TypeError: Cannot redefine property: currentProvider on the last line, error happens inside web3-core\src\index.js:42:16

Second syntax, which one can find on the net:


gives another error: TypeError: web3.eth.contract is not a function

What is the right syntax to execute contract from nodejs with geth?

2 Answers 2


Please check your web3 version with,

var Web3 = require('web3');
var web3 = new Web3();

If you get 1.0.0-beta.11 or similar (rather than 0.20.0) then you've picked up the new version. npm now installs the new version by default.

You can either go back to the older version with npm install [email protected], or consult the documentation for the new version for all the (many, many) changes.

This should answer your specific question with the new syntax:

const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');
const contract = new web3.eth.Contract(abi, '0x.....');


// install using yarn or npm
npm install web3
yarn add web3
// in node.js
var Web3Eth = require('web3-eth'),
   eth = new Web3Eth('ws://localhost:8546');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.