0
votes

I get the following error when trying to deploy my contract

Error: Migrations has not been deployed to detected network (network/artifact mismatch) at /Users/rohank2/.nvm/versions/node/v8.11.1/lib/node_modules/truffle/build/webpack:

I used truffle init to create my own truffle project. I initialized a smart contract called Migrations.

here is the code for that smart contract:

    pragma solidity ^0.4.23;

contract Migrations{

 address public admin;
  struct Bank{
    string bankname;
    string PWCcode;

  }

  struct graybarbranch{
    string branchname ;
    uint currentapr;
    uint currentdebt;
    uint amtreturned;
    uint totalborrowed;
    string bankborrowedfrom;
  }


  mapping(address=>Bank) public Banks;
  event graybar(address accountaddress,string branchname,uint totalamt);
  mapping(address=>graybarbranch) public graybarbranches;

  constructor() public {
    admin =msg.sender;
  }

  function borrow(address from, address to,uint currentapr,uint currentamt) public {
        graybarbranches[to].bankborrowedfrom=Banks[from].bankname;
        graybarbranches[to].currentapr=currentapr;
        graybarbranches[to].totalborrowed+=currentamt;
        graybarbranches[to].currentdebt=graybarbranches[to].totalborrowed-graybarbranches[to].amtreturned;
  }
  function ret(address to,uint amt) public {
    graybarbranches[to].amtreturned+=amt;
    graybarbranches[to].currentdebt=graybarbranches[to].totalborrowed-graybarbranches[to].amtreturned;
  }
  function initializebank(string bankname,string PWCcode,address ad)public{
    Banks[ad].bankname=bankname;
    Banks[ad].PWCcode = PWCcode;
  }
  function initializegraybar(address ad,string branchname) public {
    graybarbranches[ad].branchname=branchname;

    graybarbranches[ad].currentapr=0;
    graybarbranches[ad].currentdebt=0;
    graybarbranches[ad].totalborrowed=0;
    graybarbranches[ad].amtreturned=0;
  }
  function display(address ad) public{
    emit graybar(ad,graybarbranches[ad].branchname,graybarbranches[ad].totalborrowed);
  }

}

and here are the migration files:

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

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

and finally this is my truffle.js file :

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*"
    }
  }
};

No idea how to interact with the contract.

1

1 Answers

1
votes

To deploy contract on Ganache run below command: $ truffle migrate You will get txHash and contract address on console. you can use contract address to interact with Geth console.

To interact with Ganache Client, you have to install "Geth" on you machine.

Run below commands:

  1. $ geth attach http://127.0.0.1:7545
  2. You will get the "Welcome to Geth Javascript console!" message and command prompt to interact blockchain.
  3. Use eth.getCode({contract_address}) pass the contract address which you received in truffle deployment.