![](/img/trans.png)
[英]Issues with npm config & errors installing ganache-cli and truffle
[英]Unable to connect Ganache with Truffle/Npm Dev server
我能够使用Truffle和Ganache-cli。 已部署合同并可以使用松露控制台处理合同
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: ... }
现在,当我使用“ npm run dev”启动服务器时。 服务器启动正常,但未与区块链连接
我收到错误
Uncaught (in promise) Error: Contract has not been deployed to detected network (network/artifact mismatch)
这是我的truffle.js
// Allows us to use ES6 in our migrations and tests.
require('babel-register')
module.exports = {
networks: {
development: {
host: '127.0.0.1',
port: 8545,
network_id: '*', // Match any network id
gas: 1470000
}
}
}
你能指导我如何连接吗?
在您的truffle.js
,将8545
更改为7545
。
或者 ,在Ganache(GUI)中,单击右上角的齿轮,并将端口号从7545
更改为8545
,然后重新启动。 使用ganache-cli,在启动时使用-p 8545
选项将8545设置为要侦听的端口。
无论哪种方式,失配似乎都是问题所在。 这些数字应该匹配。 这是一个普遍的问题。
还可以随时查看ethereum.stackexchange.com 。 如果您想将问题移到那里,则可以对其进行标记,并留下一条消息供主持人执行。
解决问题。
问题是在currentProvider上,我给出了ganache区块链提供商的网址,并且有效。
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)
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.