2

I have tried to use web3.js with my web UI but when I run my web UI I get the below error.

enter image description here

I don't know what is the problem.

Edit

I have tried the below command while starting Geth.

geth --rinkeby --syncmode "fast" --rpc --rpcapi db,eth,net,web3,personal --cache=2048  --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*"
1

You should have started geth with cors, refer the command below.

geth --rinkeby --syncmode "fast" --rpc --rpcapi db,eth,net,web3,personal --cache=2048  --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*"
  • 1
    Thank you for your answer but it's still has the same error. – Ember Rock Mar 7 '18 at 13:11
  • Did you update the port number in the above command, its given 8545 in it and you seem to use 8042? Also, note the above command is for rinkeby network. you must remove that part if connecting to some other network – Rajesh Mar 7 '18 at 13:13
  • yeah I have change port to 8545 and the error is "Failed to load localhost:8545: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access." – Ember Rock Mar 7 '18 at 13:17
  • I mean you should have used --rpcport8042 in the given command – Rajesh Mar 7 '18 at 13:20
  • I try to use different port and also 8042 but it's has the same error. – Ember Rock Mar 7 '18 at 13:28
0

I had the same problem. The reason for this was because I opened the HTML file in a web browser i.e file://...../index.html

To fix this, I installed NodeJS with NPM and launched the website as a localhosted webpage.

Steps

  1. Install NPM
  2. Run : npm install -g http-server
  3. go to website directory and run the following in cmd : http-server
  4. go to : http://localhost:8080
-1

I have same problem and it's my fix below that work with me:

  1. Same fix as Joshua Duxbury
  2. Add MetaMask extension into Chrome, open account as following its guideline. And then select Rinkebi Test Network
  3. Get fund from https://faucet.rinkeby.io/ (following its steps) and your account on MetaMask will have some ETHs

So now you can run with Injected Web3 (that use rinkeby) or Web3 Provider (that use with testrpc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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