[英]Deploy smart contract on Ropsten network
I am trying to deploy a test contract on Ropsten network.我正在尝试在 Ropsten 网络上部署测试合同。 I am using metamask, infura and truffle to create and test the contract.我正在使用 metamask、infura 和 truffle 来创建和测试合约。 My folder structure looks like this我的文件夹结构是这样的
My migration file has following codes我的迁移文件有以下代码
const TestContract = artifacts.require("TestContract");
module.exports = function(deployer) {
deployer.deploy(TestContract);
};
When i run truffle migrate i am getting following error Could not find artifacts for Migrations from any sources当我运行 truffle migrate 时,我收到以下错误无法从任何来源找到迁移的工件
My truffle-config.js look like this我的 truffle-config.js 看起来像这样
const HDWalletProvider = require('truffle-hdwallet-provider')
module.exports = {
networks: {
ropsten: {
provider: function() {
return new HDWalletProvider("Mnemonic key", "https://ropsten.infura.io/v3/API_KEY")
},
network_id: 3,
gas: 4000000
}
},
contracts_directory: './src/contracts/',
contracts_build_directory: './src/abis/',
compilers: {
solc: {
optimizer: {
enabled: true,
runs: 200
}
}
}
}
You need to have Migrations
contract in your contracts folder:您需要在您的合同文件夹中有Migrations
合同:
pragma solidity >=0.4.25 <0.6.0;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
constructor() public {
owner = msg.sender;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
Also a 1_initial_migration.js
in your migrations folder:还有一个1_initial_migration.js
在您的迁移文件夹中:
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.