I am unable to connect Ganache with Truffle Npm Dev server Pls help

+4 votes

I am unable to work with Truffle and Ganache-cli. Have deployed the contract and can play with that using truffle console:

truffle(development)> { tx:
   { transactionHash:
     transactionIndex: 0,
     blockNumber: 10,
     gasUsed: 28387,
     cumulativeGasUsed: 28387,
     contractAddress: null,
     logs: [],
     status: '0x01',
     logsBloom: ... }

Now when i started a server using "npm run dev". Server started fine but is not connecting with the Blockchain and I am getting the error:

Uncaught (in promise) Error: Contract has not been deployed to detected network (network/artifact mismatch)
Can you please guide me on how to connect ?
Mar 26, 2018 in Blockchain by Christine
• 15,790 points

retagged Nov 23, 2018 by Omkar 1,206 views

2 answers to this question.

+2 votes

The issue is at CurrentProvider. Give the url of ganache blockchain provider and it'll work.

if (typeof web3 !== 'undefined') {
console.warn("Using web3 detected from external source like Metamask")
// Use Mist/MetaMask's provider
// window.web3 = new Web3(web3.currentProvider);
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));

  } else {
console.warn("No web3 detected. Falling back to http://localhost:8545. You should remove this fallback when you deploy live, as it's inherently insecure. Consider switching to Metamask for development. More info here: http://truffleframework.com/tutorials/truffle-and-metamask");
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
answered Mar 26, 2018 by Perry
• 17,100 points

edited Oct 11, 2018 by Omkar
+1 vote

You can try running truffle compile (and/or truffle migrate) with the --reset flag.

answered Oct 11, 2018 by pappu

Related Questions In Blockchain

+1 vote
1 answer

I am unable to change port of composer-rest-server. Please help!

Use full format for running a business ...READ MORE

answered Mar 27, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer

How to connect to *coin RPC-Server with PHP

If you want to connect inside your ...READ MORE

answered Sep 12, 2018 in Blockchain by slayer
• 29,310 points
+1 vote
0 answers
+1 vote
1 answer

Unable to send payment using API. Please help.

Firstly, check your passwords, your API code and your wallet ...READ MORE

answered Apr 3, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
+1 vote
1 answer