在Ropsten网络上部署智能合约

时间:2019-12-05 03:04:06

标签: blockchain ethereum solidity truffle

我正在尝试在Ropsten网络上部署测试合同。我正在使用metamask,infura和松露创建和测试合同。我的文件夹结构看起来像这样

My folder structure looks like this

我的迁移文件具有以下代码

const TestContract = artifacts.require("TestContract");

module.exports = function(deployer) {
  deployer.deploy(TestContract);
};

当我运行松露迁移时,出现以下错误 找不到任何来源的迁移工件

我的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
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您需要在合同文件夹中拥有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);
  }
}

您的迁移文件夹中还有一个1_initial_migration.js

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};