Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.
This repository has been archived by the owner on May 26, 2022. It is now read-only.

CONNECTION ERROR: Couldn't connect to node http://localhost:8545. #114

Closed
martin-tian opened this issue Nov 18, 2016 · 7 comments
Closed

Comments

@martin-tian
Copy link

I tried to use Web3 to call smart Contract in html file, reported the following error, ERROR: Couldn't connect to node http://localhost:8545. smart, who can help me? like this:

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); //it's not work

@himanshuoodles
Copy link

same here

@jocot
Copy link

jocot commented Jan 31, 2017

I had this error as well in an ubuntu 16.04 VM running under vagrant/virtualbox.

Running the node console as root user (eg. sudo node) worked for me.

@ChihChengLiang
Copy link

if you are using parity, add parity ui --chain dev --rpccorsdomain "*" works for me

@Ollemesh
Copy link

I had the same trouble and spend a lot of time to find the reason.
web3.js has XMLHttpRequest (npm module) as a dependency. This module writes some temp files when sends a request.
(see here: xmlhttprequest source )

It means your NodeJs process needs to write files permission

web3.js ignore original error message here
We can see how error in catch arguments do not use in throwing error

@JadenGu
Copy link

JadenGu commented Sep 19, 2018

I had the same trouble and spend a lot of time to find the reason.
web3.js has XMLHttpRequest (npm module) as a dependency. This module writes some temp files when sends a request.
(see here: xmlhttprequest source )

It means your NodeJs process needs to write files permission

web3.js ignore original error message here
We can see how error in catch arguments do not use in throwing error

Hi @Ollemesh , Could you explain how to add write permission for NodeJS process? I'm new to Node. Thx a lot.

@isaack2808
Copy link

isaack2808 commented Dec 14, 2018

Running sudo chmod 777 /var/www/html/edit2/truffle
then sudo truffle console --network rinkeby
and then web3.eth.getBlock('latest')

If you get a response like this:

{ difficulty: BigNumber { s: 1, e: 0, c: [ 1 ] },
extraData: '0xd683010900846765746886676f312e3130856c696e7578000000000000000000630f85831de3105cf43799696541103a96941275c8e5746580ef3231f6e47a51228a319ae7fa60ad8bda1844422a60354e45e2a15df49db445bfd806096c5b6d00',
gasLimit: 7005011,
gasUsed: 1844149,
hash: '0x18cc97e7dac1932d8104b81d92f95af0a55bb1e911e5e8661c4ff8b68010ddf3',
logsBloom: '0x00000000200802008000400000010001200002000800002800000000200000000000008001045000030000302200000000000000020080000000000010000000000000800000000002000008008000003000080000000020004000000040000000002000020000002000000000000800000000000002050080000030000000000000148002000000400000000000000000000000040000008008280000000000000000000000000000440000400400000002000000800000100000000200400000000002000000000010800000000000020000000000000082008080200032100010000200000008000040080520000000000008400080001000080080010000',
miner: '0x0000000000000000000000000000000000000000',
mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
nonce: '0x0000000000000000',
number: 3512315,
parentHash: '0xf3f7579192f06e28f9c6e6b03d4862fc4be7968f58ac9688792a7f9a2de543a9',
receiptsRoot: '0xcf0e838d18581a9e542fa9b9937a2376d3bca7b70c94ebaf8564219df66eebc6',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 6334,
stateRoot: '0x07bf31b040ef80f45cd89591359757edb85449ba0488b49b9813bd112156648b',
timestamp: 1544813447,
totalDifficulty: BigNumber { s: 1, e: 6, c: [ 6484524 ] },
transactions:
[ '0x2995dafec094185814c8d433c82d5020576967f462c5f5e7f95d32bc0fdbfc7f',
'0x98b28dc9f13d56612633eaec6793b96eeff7178d9ae98808a56e7d7ea176f736',
'0x69d5e95796e08826d5c48320c6003a44d9ca4b2aea1d2cbb77b91f89eed382ac',
'0xc8ea21cde9386c176e8d4bfe6c337b9b34e7281517142619fbb59bc7b3806a59',
'0xcf941fc2bd349bad961e59b00c03d0e75f78d95daab9a155a92cbf2dff61c177',
'0x99a9a2991d67feead60500db82d3ca0a8719c6e8871d5f7c4f5c7add74f4b7a1',
'0x4d3e6a63a64aca109178a50bba33b8cf9feb96a3d8003a156a5e484669426477',
'0x141da6a8ed7cc559e4e54929f4648dde552ee75db43b36d08cc6e00df4f33b6f',
'0xad82cefda7562218651440f2022be0ac7947cccc73723403898b32ab1b6d2b25',
'0xf0205a4faba196d4a488b83c5ce870411adfac03b7deeb198830c0b585bc4c55',
'0x1e77fadd5f7b402421b61aaa520fffc2640caa4875f91b2ce323fec5ed048aeb',
'0xd2da5b018b3125e63b8b2e46fe5d0831c1de83d1e0293c7c50c8f2b3dcd001d3',
'0x14546528a3103e6253aeaf7b1e72cb5db53dca9e60d26282023519ff826f1110' ],
transactionsRoot: '0xa06c14550cdf64c77def46de733f4d1314dc6b40eba3eafd1dd8097eb76b3629',
uncles: [] }

then you've connected to the local node at http://127.0.0.1:8545

@RapiDash1
Copy link

Do what @Ollemesh suggested. Paste npm i xmlhttprequest in the terminal. This worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants