I'm developing a Dapp using truffle and I need to connect to a contract that I uploaded on rinkeby using truffle migrate --network rinkeby. Problem is that I'm unable to connect to the rinkeby network from the web3 interface. I run a rinkeby local node using

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --rpcport 8545 --rpcaddr localhost --rpccorsdomain "*" --unlock="0x4A1b47b0b119AFD421ec4E3b5B54D8EF5141b59c"

The front-end code is

if (typeof web3 !== 'undefined'){
        web3 = new Web3(web3.currentProvider);
        web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

But the code always slaps me with

Error: Provider not set or invalid.

How can I resolve this issue and how to create a new contract instance from contract abi?

  • have you tried --rpcaddr this has worked for me in the past though I can't remember why, hence the comment instead of a full answer!
    – TC8
    Mar 15 '18 at 9:13
  • Have you set the provider in the truffle.js file? If not here is the code rinkeby: { host: "localhost", port: 8545, network_id: 4, from: "address", gas: gas }
    – Gabe
    Mar 15 '18 at 10:47

Dapp using truffle and local server this commend run:

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --rpcport 8545 --rpcaddr "http://localhost:8000" --rpccorsdomain "*" --unlock="0x4A1b47b0b119AFD421ec4E3b5B54D8EF5141b59c"

and try it http://localhost:8000

Rpc domain --rpc --rpccorsdomain "http://localhost:8000" then run project

  • It is not working either. Feb 10 '18 at 7:47
  • I tried this geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --rpcport 8545 --rpcaddr localhost --rpccorsdomain "http://localhost:8000" --unlock="0x4A1b47b0b119AFD421ec4E3b5B54D8EF5141b59c". Please correct me if I'm wrong. Feb 10 '18 at 7:59
  • geth --networkid 20 --port 60303 --rpc --rpccorsdomain "localhost:8000" --lightkdf --cache 16 --datadir "D:\Database\final_chain_database" console this commend run and genesis file inti then this commend run then "npm start " Feb 10 '18 at 8:26
  • The problem persists. I would like to hear what is going wrong here, then explain to me how I can fix the problem. Feb 10 '18 at 8:43
  • What version of web3? 95% of the issues I've been having recently are due to the breaking changes between v0.x and v1.0(which is now installed by default). If your web3 version is v1.x try switching to v0.20.x or v0.19.x. The way you have the front end code the v1 will most likely fail (trust me, been a month long headache haha)
    – ryanh
    Feb 10 '18 at 20:03

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.