![](/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.