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)>
Voting.deployed().then(function(contractInstance)
{contractInstance.voteForCandidate('Rama').then(function(v)
{console.log(v)})})
undefined
truffle(development)> { tx:
'0xe4f8d00f7732c09df9e832bba0be9f37c3e2f594d3fbb8aba93fcb7faa0f441d',
  receipt:
   { transactionHash:
'0xe4f8d00f7732c09df9e832bba0be9f37c3e2f594d3fbb8aba93fcb7faa0f441d',
     transactionIndex: 0,
     blockHash:
'0x639482c03dba071973c162668903ab98fb6ba4dbd8878e15ec7539b83f0e888f',
     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 22, 2018 by Omkar 214 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+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
• 16,450 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
206 views
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,040 points
67 views
+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
92 views
+1 vote
1 answer

How can I connect to the specified nodes using IPFS?

You can actually connect to the specific ...READ MORE

answered Apr 25, 2018 in Blockchain by Christine
• 15,790 points
310 views
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
62 views
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 ariaholic
• 7,320 points
42 views
+1 vote
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.