【问题标题】:Error: SimpleSmartContract has not been deployed to detected network (network/artifact mismatch)错误:尚未将 SimpleSmartContract 部署到检测到的网络(网络/工件不匹配)
【发布时间】:2021-04-03 14:21:00
【问题描述】:

我开发了一个简单的智能合约。当我运行松露测试时,它显示以下错误:我是新手,所以我无法弄清楚。

PS F:\pracdap> 松露测试

Compiling your contracts...
===========================
√ Fetching solc version list from solc-bin. Attempt #1
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\SimpleSmartContract.sol       
√ Fetching solc version list from solc-bin. Attempt #1
> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "urce file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more informa
--> /F/pracdap/contracts/SimpleSmartContract.sol


> Artifacts written to C:\Users\HP\AppData\Local\Temp\test--1224-GWVOn3NGyps8
> Compiled successfully using:
   - solc: 0.8.3+commit.8d00100c.Emscripten.clang



  Contract: SimpleSmartContract
    1) should be deployed
    > No events were emitted


  0 passing (128ms)
  1 failing

  1) Contract: SimpleSmartContract
       should be deployed:
     Error: SimpleSmartContract has not been deployed to detected network (network/artifact mismatch)
      at Object.checkNetworkArtifactMatch (F:\node\node_modules\truffle\build\webpack:\packages\contract\lib\utils\index.js
      at Function.deployed (F:\node\node_modules\truffle\build\webpack:\packages\contract\lib\contract\constructorMethods.j
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at Context.<anonymous> (test\simpleSmartContract.js:5:33)

实体代码

pragma solidity >=0.4.22 <0.9.0;

contract SimpleSmartContract {
}

节点 js。测试代码

const SimpleSmartContract = artifacts.require('SimpleSmartContract');

contract('SimpleSmartContract', () => {
    it('should be deployed', async () => {
        const simpleSmartContract = await SimpleSmartContract.deployed();
        assert(simpleSmartContract.address !== '');
    });
});

【问题讨论】:

  • 欢迎来到 StackOverflow。请编辑您的问题,使其包含产生错误的可重现代码(在您的情况下,这可能是 Solidity 合同和 javascript 测试/部署程序)。您可以在How to Ask 部分找到更多提示。
  • @Pete Hejda 解决方案?

标签: solidity truffle network-error-logging


【解决方案1】:

您似乎没有为您的SimpleSmartContract 添加迁移文件。 在 Migrations 目录中创建一个名为 2_deploy_contracts.js 的文件。在其中添加以下代码:

const SimpleSmartContract = artifacts.require("SimpleSmartContract"); module.exports = 功能(部署者){ deployer.deploy(SimpleSmartContract); };

然后尝试运行测试。

【讨论】:

    【解决方案2】:

    尝试使用迁移...如果显示任何错误,请告诉我。

    【讨论】:

      【解决方案3】:
      const SimpleSmartContract = artifacts.require("SimpleSmartContract");
      
      module.exports = async function(deployer, _network, accounts) {
        await deployer.deploy(SimpleSmartContract);
      };
      

      您应该在迁移文件夹中创建一个新的“迁移文件”,其(可能)名称为 2_deploy_contracts.js。

      异步函数参数:

      deployer:合约部署
      _network:指定网络(truffle-config.js)
      accounts:部署时访问松露账户(I.E Solidity 构造函数参数)

      参考:https://trufflesuite.com/docs/truffle/getting-started/running-migrations.html

      【讨论】:

        猜你喜欢
        • 2018-07-19
        • 2018-06-21
        • 2021-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-18
        • 1970-01-01
        相关资源
        最近更新 更多