When MetaMask tries to access my local testrpc, I'm getting the following error in the browser:

contract.js:424 Uncaught (in promise) Error: UnitManager has not been deployed to detected network (1509577107908)

Here is my 2_deploy_contracts.js:

var UnitManager = artifacts.require("./UnitManager.sol");

module.exports = function(deployer) {
  // deployer.deploy(UnitManager)
  let hash = ''
  .then( () => {
    return UnitManager.new()
  .then( instance => {
    instance.setRole(web3.eth.accounts[1], 3, {from: web3.eth.accounts[0]})
    return instance
  // ...

I've tried to set the network id explicitly (you can see that in my error) in truffle.js and in the command $ testrpc -i 1509577107908.

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

Notice that I'm not using the standard deployer.deploy() command. I'm using new() because I need the instance object to run subsequent commands in deployment.

What am I missing here?


You can still use deployer and make an instance that you can call functions on. I wouldn't use new() if it is giving you problems, this seems like it was made for testing not deployment (after reading their documentation)

You can use deployer in this manner:

    var instance = ContractA.at(ContractA.address);
    return instance.doFunction(param1, param2);
| improve this answer | |
  • Yes, this is the method I used today more or less. This solved the problem. Thanks! – Eric Miller Nov 3 '17 at 18:16

It strikes me that you have a line commented out:

// deployer.deploy(UnitManager)

This line seems to deploy the UnitManager contract, the same one that the error says is not deployed. Seems like a likely candidate!

| improve this answer | |
  • The .new() function deploys - I just don't know where. The rest of my script runs very specific state-changing functions that pass. Maybe it's deploying in memory and waiting to send to testrpc until I run .deployer()? – Eric Miller Nov 3 '17 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.