Go-Ethereum

我已經部署了我的智能合約,但我無法使用 truffle 與之互動

  • October 1, 2018

我的 ChainList.sol 程式碼

pragma solidity ^0.4.23;

contract ChainList  {

 struct  data  {
   uint   ownernumber;
   uint   id;
 }

 uint value;
 mapping (uint256 => data) public  datamatching;

 function storedata (uint _ownernumber, uint _id) public {
   var  persondata  = datamatching[value];
   persondata .ownernumber = _ownernumber;
   persondata. id  =  _id;
 }

 function getData(uint256 userId) returns (uint, uint){
   return (datamatching[userId].ownernumber, datamatching[userId].id);
 }
}

// 使用遷移部署合約

var ChainList = artifacts.require("./Migrations.sol");

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

// 我的 truffle.js 程式碼

module.exports = {
 networks: {
   development: {
     host: "localhost",
     port: 8545,
     network_id: "*" // Match any network id
   }
 }
};

我已經成功部署

Compiling ./contracts/ChainList.sol...
Compiling ./contracts/Migrations.sol...

Compilation warnings encountered:

/

home/mdvenkatesh/Desktop/asset/contracts/ChainList.sol:14:5: Warning: Use of the "var" keyword is deprecated.
   var  persondata  = datamatching[value];
   ^-------------^
,/home/mdvenkatesh/Desktop/asset/contracts/Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.

**Running migration: 1_initial_migration.js
 Deploying Migrations...
 ... 0x942947d411cc40c214ee717f12a8626033aea99b9db0cfda2189a8c214c0d068
 Migrations: 0x4d838fd69456fcb2c4c49b1b05c8ae7b7205cde5
Saving successful migration to network...
 ... 0x20659b7fdf1ac7c4a1899be68938297b5fb1cae318024c61eee7886d007d134d
Saving artifacts...
Running migration: 2_deploy_contracts.js
 Replacing Migrations...
 ... 0xe287e9ccbe891349ca0a2b1bac64a1291558b3817a6689431bf88721122eb7c1
 Migrations: 0xcc3979c6af9f5003445f26e5c1dfdc140bba29c5
Saving successful migration to network...
 ... 0x2a3b60f8cf3571ef12bb81ea5c80d22b6e2febae8e38f2dd0c05e0f147137305
Saving artifacts...**

現在我試圖用松露吸引我收到以下錯誤

ChainList.deployed().then(function(instance){app= instance });

Error: ChainList has not been deployed to detected network (network/artifact mismatch)
   at /usr/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/contract.js:454:1

我想我遵循了所有步驟,但我不知道出了什麼問題,請幫助我

你搞砸了你的部署腳本。最後,您的/migrations/文件夾中應該有 2 個文件:

  1. 1_initial_migration.js
var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
 deployer.deploy(Migrations);
};
  1. 2_deploy_contracts.js
var ChainList = artifacts.require("/path/to/ChainList.sol");

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

在您的範例中,您將遷移變數更改為“ChainList”,但您仍然指向./Migrations.sol. 只需將其更改為指向您的契約文件即可。

引用自:https://ethereum.stackexchange.com/questions/59790