[英]contract has not been deployed to detected network (network/artifact mismatch) on Rinkeby Network
I have been running into the specified in the title.我一直遇到标题中指定的。
I have developed a smart contract and have successfully compiled and deployed it to the.network as follows: 1. Run testrpc 2. truffle compile 3. truffle migrate我开发了一个智能合约,已经成功编译部署到.network中,如下: 1. 运行testrpc 2. truffle compile 3. truffle migrate
However, the error above is still being shown.但是,仍然显示上述错误。 I then tried deleting the build file and followed the steps below: 1. Run testrpc 2. truffle compile 3. truffle migrate -.network rinkeby
然后我尝试删除构建文件并按照以下步骤操作: 1. 运行 testrpc 2. truffle compile 3. truffle migrate -.network rinkeby
The error was still being shown.错误仍在显示。
Below is the truffle.js file下面是 truffle.js 文件
module.exports = {
migrations_directory: "./migrations",
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
rinkeby: {
host: "localhost", // Connect to geth on the specified
port: 8545,
network_id: "*",
}
} }; } };
If anybody has faced any similar issues and have resolved it, I would greatly appreciate it if you could share how you have resolved it.如果有人遇到任何类似的问题并已解决它,如果你能分享你是如何解决它的,我将不胜感激。
Thanks in advance提前致谢
I had the same issue and created the file 2_deploy_contract.js in the migration folder with the code:我遇到了同样的问题,并使用以下代码在迁移文件夹中创建了文件 2_deploy_contract.js:
var myContract = artifacts.require("myContract");
module.exports = function(deployer){
deployer.deploy(myContract);
}
I also checked the truffle-config.js at the root of the folder with the default settings:我还使用默认设置检查了文件夹根目录下的 truffle-config.js:
rinkeby: {
host: "localhost",
port: 8545,
from: "0x0085f8e72391Ce4BB5ce47541C846d059399fA6c", // default address to use for any transaction Truffle makes during migrations
network_id: 4,
gas: 4612388 // Gas limit used for deploys
}
For me, the following steps worked: create the file 2_deploy_contract.js in the migration folder with the code对我来说,以下步骤有效:使用代码在迁移文件夹中创建文件 2_deploy_contract.js
var myContract = artifacts.require("myContract");
module.exports = function(deployer){
deployer.deploy(myContract);
}
And run on terminal并在终端上运行
$ truffle migrate --reset
I didn't need to change any settings in the truffle-config.js我不需要更改 truffle-config.js 中的任何设置
There are a lot of different error messages through the original post and the comments.通过原始帖子和评论有很多不同的错误消息。 I think the best thing is to provide a step-by-step guide to deploying to Rinkeby using Truffle:
我认为最好的方法是提供使用 Truffle 部署到 Rinkeby 的分步指南:
Geth格思
To start, create the account you want to use for this test.首先,创建要用于此测试的帐户。 It looks like you've already done this, but including this for completeness.
看起来您已经完成了此操作,但为了完整起见,将其包括在内。 Note, that I am using a custom keystore directory because I like to keep my keystores separate across different networks.
请注意,我使用自定义密钥库目录是因为我喜欢将密钥库分开在不同的网络中。
geth --rinkeby --keystore ./eth/accounts/rinkeby/keystore account new
After entering your password, you will get back your new address.输入密码后,您将取回新地址。 Once the account is created, create a new text file called pass.txt and put the password you used to create the account inside the file and save it.
创建帐户后,创建一个名为 pass.txt 的新文本文件,并将用于创建帐户的密码放入该文件并保存。
Obviously this is not the preferred way of keeping passwords safe.显然,这不是保持密码安全的首选方式。 Do not do this in a live environment
不要在现场环境中这样做
You'll also need to add some ether to your account.您还需要向您的帐户添加一些以太币。 Use faucet.rinkeby.io .
使用faucet.rinkeby.io 。
Next, make sure you are properly starting starting Geth and it's in the correct state.接下来,确保您正确启动 Geth 并且它处于正确状态。 I use custom data and keystore directories.
我使用自定义数据和密钥库目录。 You can use the default if you choose.
如果您选择,您可以使用默认值。
geth --rpc --datadir ./eth/geth/data/rinkeby --keystore ./eth/accounts/rinkeby/keystore --rinkeby --rpccorsdomain '*' --rpcapi 'web3,eth,net,personal' --unlock '0x25e6C81C823D4e15084F8e93F4d9B7F365C0857d' --password ./pass.txt --syncmode="full" --cache=1024
Replace my address with the one you created.用你创建的地址替换我的地址。 When started, you should see something like this:
开始时,您应该看到如下内容:
INFO [02-13|17:47:24] Starting peer-to-peer node instance=Geth/TrustDevTestNode/v1.7.3-stable-4bb3c89d/windows-amd64/go1.9
INFO [02-13|17:47:24] Allocated cache and file handles database=C:\\cygwin\\home\\adamk\\eth\\geth\\data\\rinkeby\\geth\\chaindata cache=1024 handles=1024
INFO [02-13|17:47:47] Initialised chain configuration config="{ChainID: 4 Homestead: 1 DAO: <nil> DAOSupport: true EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 1035301 Engine: clique}"
INFO [02-13|17:47:47] Initialising Ethereum protocol versions="[63 62]" network=4
INFO [02-13|17:47:47] Loaded most recent local header number=1766839 hash=6d71ad…ca5a95 td=3285475
INFO [02-13|17:47:47] Loaded most recent local full block number=1766839 hash=6d71ad…ca5a95 td=3285475
INFO [02-13|17:47:47] Loaded most recent local fast block number=1766839 hash=6d71ad…ca5a95 td=3285475
INFO [02-13|17:47:47] Loaded local transaction journal transactions=0 dropped=0
INFO [02-13|17:47:47] Regenerated local transaction journal transactions=0 accounts=0
INFO [02-13|17:47:48] Starting P2P networking
2018/02/13 17:47:50 ssdp: got unexpected search target result "upnp:rootdevice"
2018/02/13 17:47:50 ssdp: got unexpected search target result "uuid:2f402f80-da50-11e1-9b23-001788409545"
2018/02/13 17:47:50 ssdp: got unexpected search target result "urn:schemas-upnp-org:device:basic:1"
2018/02/13 17:47:50 ssdp: got unexpected search target result "upnp:rootdevice"
2018/02/13 17:47:50 ssdp: got unexpected search target result "uuid:2f402f80-da50-11e1-9b23-001788409545"
INFO [02-13|17:47:51] UDP listener up self=enode://751bc7825c66f9ab5b87f933d6b6302fd14434b7ed4d7c921c3f39684915843078eda4e995c927561067946b4f856ca2a35ea7285c27439c0f535338aaca80e9@172.88.30.226:30303
INFO [02-13|17:47:51] RLPx listener up self=enode://751bc7825c66f9ab5b87f933d6b6302fd14434b7ed4d7c921c3f39684915843078eda4e995c927561067946b4f856ca2a35ea7285c27439c0f535338aaca80e9@172.88.30.226:30303
INFO [02-13|17:47:51] IPC endpoint opened: \\.\pipe\geth.ipc
INFO [02-13|17:47:51] HTTP endpoint opened: http://127.0.0.1:8545
INFO [02-13|17:47:52] Unlocked account address=0x25e6C81C823D4e15084F8e93F4d9B7F365C0857d
Truffle松露
truffle.js (or truffle-config.js if Windows): truffle.js(或 truffle-config.js,如果是 Windows):
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
rinkeby: {
host: "localhost",
port: 8545,
from: "0x25e6c81c823d4e15084f8e93f4d9b7f365c0857d",
network_id: "4"
}
}
};
Use Truffle console to confirm your node and account:使用 Truffle 控制台确认您的节点和帐户:
$ truffle console --network rinkeby
truffle(rinkeby)> web3.eth.blockNumber
1767136 // Confirm latest block number on https://rinkeby.etherscan.io/
truffle(rinkeby)> web3.eth.getBalance('0x25e6c81c823d4e15084f8e93f4d9b7f365c0857d');
{ [String: '2956062100000000000'] s: 1, e: 18, c: [ 29560, 62100000000000 ] }
Exit the console and run your compile/migrations (this will take about a minute to run):退出控制台并运行您的编译/迁移(这将需要大约一分钟才能运行):
$ truffle migrate --network rinkeby
Compiling .\contracts\LoopExample.sol...
Writing artifacts to .\build\contracts
Using network 'rinkeby'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0xf377be391a2eaff821c0405256c6a1f50389650ea9754bdc2711296b02533e02
Migrations: 0x9cef8d8959d0611046d5144ec0439473ad842c7c
Saving successful migration to network...
... 0x4cf989973ea56a9aa4477effaccd9b59bfb80cc0e0e1b7878ff25fa5cae328db
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying LoopExample...
... 0x4977c60fd86e1c4ab09d8f970be7b7827ee25245575bfbe206c19c6b065e9031
LoopExample: 0x56b9c563f287cdd6a9a41e4678ceeeb6fc56e104
Saving successful migration to network...
... 0x5628d64dc43708ccb30d7754a440e8e420a82a7b3770539cb94302fe7ad9098f
Saving artifacts...
Confirm the deployment on etherscan: https://rinkeby.etherscan.io/address/0x56b9c563f287cdd6a9a41e4678ceeeb6fc56e104在etherscan上确认部署: https ://rinkeby.etherscan.io/address/0x56b9c563f287cdd6a9a41e4678ceeeb6fc56e104
I came across the same problem and the following solved it for me:我遇到了同样的问题,以下为我解决了这个问题:
...configuring the 1_initial_migration.js to deploy the TodoList contract for this to work. ...配置 1_initial_migration.js 以部署 TodoList 合约以使其工作。 When doing the truffle init it deploys a Migration.sol contract, so you have to change that:
在执行 truffle init 时,它会部署一个 Migration.sol 合约,因此您必须更改它:
var TodoList = artifacts.require('../contracts/TodoList.sol');
module.exports = function(deployer) {
deployer.deploy(TodoList);
}
source: https://medium.com/@addibro/i-had-to-fiddle-around-with-truffle-compile-and-migrate-first-and-also-configuring-the-9bc7a6ea8e3e来源: https : //medium.com/@addibro/i-had-to-fiddle-around-with-truffle-compile-and-migrate-first-and-also-configuring-the-9bc7a6ea8e3e
Tl;dr: Tl;博士:
2_deploy_contract.js
2_deploy_contract.js
PS: you can name it whatever. PS:你可以随便命名。 2_deploy_yourmomsdonuts.js would work too.
2_deploy_yourmomsdonuts.js 也可以。 Just pay attention to the number - it has to correspond with the order.
只需注意数字 - 它必须与订单相对应。 2. Add this code snipper to this file:
2. 将此代码片段添加到此文件:
Replace HelloWorld with the name of your contract that didn't get deployed (see in your console what contract has thrown an error)将 HelloWorld 替换为未部署的合约名称(在控制台中查看哪个合约引发了错误)
var HelloWorld = artifacts.require('HelloWorld'); module.exports = function (deployer) { deployer.deploy(HelloWorld); };
Run truffle migrate --reset
or truffle deploy --reset
- These are aliases and do the same thing.运行
truffle migrate --reset
或truffle deploy --reset
- 这些是别名,做同样的事情。 You can also run both of them to be on the safe side.您也可以同时运行它们以确保安全。
You should see that your contract got deployed to your network.您应该看到您的合同已部署到您的网络。
Finally truffle console
and invoke your function again.最后
truffle console
并再次调用您的函数。 Voila.瞧。
Why did you have to manually add a migration?为什么必须手动添加迁移? The problem was that your smart contract didn't get deployed/did't get recognized so by manually adding your migration, you are telling Truffle which file should get deployed.
问题是你的智能合约没有被部署/没有被识别,所以通过手动添加你的迁移,你告诉 Truffle 应该部署哪个文件。
I found the solution for this problem.我找到了解决这个问题的方法。 i change my migration file name from AdvancedStorage_migrate.js to 2_AdvancedStorage_migrate.js
我将迁移文件名从 AdvancedStorage_migrate.js 更改为 2_AdvancedStorage_migrate.js
truffle can't able find a migration file if you didn't save your migration file without number so, you must be save your migration file like this(2_AdvancedStorage_migrate.js )如果您没有保存没有编号的迁移文件,松露将无法找到迁移文件,因此,您必须像这样保存迁移文件(2_AdvancedStorage_migrate.js)
this problem is not rise from truffle configuration so don't touch truffle configuration.js file这个问题不是由 truffle 配置引起的,所以不要触摸 truffle configuration.js 文件
Solution:解决方案:
In My case I am using truffle-contract to load contract abi.在我的例子中,我使用 truffle-contract 来加载合同 abi。 By default truflle-contract.network id is 1.
默认情况下,truflle-contract.network id 为 1。
But I am using goreli.network id 5. We need to setNetwork while loading contract `但我使用的是 goreli.network id 5。我们需要在加载合同时设置网络`
const contract = require('truffle-contract');
const MyContract = contract(MyContract);
MyContract.setProvider(web3.currentProvider);
MyContract.setNetwork(5)
` `
const conract = artifacts.require('conractArtifact'); //update this module.exports = function (deployer) {} //to this module.exports = async (deployer) => {} //or to this module.exports = fucntion (deployer) {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.