question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deployment of multiple contracts not recorded in JSON files

See original GitHub issue
  • I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

Probably the same issue as in https://github.com/trufflesuite/truffle/issues/713. My contracts are interdependent, with some taking constructor arguments of the addresses of others. However, the workaround did not work for me; chaining the promises to run one after the other led to the same issue as separating them into different migrations.

Steps to Reproduce

truffle migrate --reset truffle console

Dummy.deployed()

Expected Behavior

I expect that Dummy.deployed() will give a thenable that I can use to access the deployed instance of Dummy. Ganache indicates that the contract deployment was successful (and all deployments succeeded in Remix), but Truffle doesn’t seem to remember this. In fact none of the [X]Coin contracts exist in Truffle’s mind; running ACoin.deployed() or FirstCoin.deployed() gives the same error, but Dummy in this case is an almost empty contract:

contract Dummy {
    function Dummy() public {}
}

Migrations 2 and 3 deploy the data and support contracts that function properly. Migration 4 deploys the first currency contract; this is the first contract that can’t be found. Migration 5 tries to deploy the rest, which can’t be found either.

Actual Results

Sometimes this happens:

Error: The contract code couldn't be stored, please check your gas amount.
    at Object.callback (/usr/lib/node_modules/truffle/build/cli.bundled.js:328412:46)
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:37990:25
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:330356:9
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:176198:11
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:326008:9
    at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/cli.bundled.js:329052:7)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/cli.bundled.js:176427:18)
    at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/cli.bundled.js:176717:12)
    at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/cli.bundled.js:176872:12)
    at IncomingMessage.<anonymous> (/usr/lib/node_modules/truffle/build/cli.bundled.js:176832:24)

but re-running truffle migrate --reset seems to fix the issue. This is not the main issue.

Compiling ./contracts/ERC20.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/libraries/ITT/Math.sol...
Writing artifacts to ./build/contracts

Using network 'development'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0xc8ccb8fad6c9556a24d7e18ee223835c3b42382fb22fbfe7092f9f61550f4460
  Migrations: 0xbd2c938b9f6bfc1a66368d08cb44dc3eb2ae27be
Saving successful migration to network...
  ... 0xcd6eeb5bec35d4799909d5715cf44925a766a50d0e16dd1335253a006f4a3453
Saving artifacts...
Running migration: 2_deploy_data.js
  Replacing DataContract...
  ... 0x16218bf15f1a99c37814235955550878a6042741462e1e194a10ed58ddd4081a
  DataContract: 0x8acee021a27779d8e98b9650722676b850b25e11
Saving successful migration to network...
  ... 0x826afc1973ce8c2b0a3d54fb4804046aba83adb18f392cbad1f28953614a979a
Saving artifacts...
Running migration: 3_deploy_itt.js
  Replacing ITT...
  ... 0x3d403e85e1ee8836b5984230a865b01d34eb36df5bf1bf246807c9178951d0e9
  ITT: 0x4e71920b7330515faf5ea0c690f1ad06a85fb60c
Saving successful migration to network...
  ... 0x992da3cce5f8a6ee49f176f32dcdf629f8031c6056c81bf9325e211e14d96f5b
Saving artifacts...
Running migration: 4_deploy_first_currency.js
Saving successful migration to network...
  Deploying FirstCoin...
  ... 0x7d6e201bc467648d504bfe092bff8e4579ffef5775905ced095e5235e89e1717
Saving artifacts...
  ... 0xb25af8583898ca36c75b2d4436a584665f6cf998db5be229b1ccf01d9047f534
Running migration: 5_deploy_other_currencies.js
Saving successful migration to network...
  Deploying ACoin...
  Deploying BCoin...
  Deploying CCoin...
  Deploying DCoin...
  Deploying ECoin...
  Deploying FCoin...
  Deploying GCoin...
  Deploying HCoin...
  Deploying ICoin...
  Deploying Dummy...
  FirstCoin: 0xd54b47f8e6a1b97f3a84f63c867286272b273b7c
  ... 0x03632a240b2d5c582304e61b1d78e6d5c1f31cff0d7a54469e8b7c380988452b
Saving artifacts...
  ... 0x29ab839997160936d574af0d1bfc892eaf1ec8147313a83490930f03a2950bb6
Running migration: 6_register_currencies.js
  ... 0x150d4dc42f83c0ddb6178e3ed9076ecb4394ebacc6b736217d8abec9ecf40f40
Saving successful migration to network...
  ... 0xe4b22072becf51c29e1f982c2a91dfacd8070371d26af3a1fef4164f68c6fe3f
  ... 0xc00494997f8fc1e88be93fc86573452c80b89010cd524278d10f7296b7ce606a
  ... 0xfaeac5c9395482f4d8a8b310ffe184b05621a3ebbb1aef244f2a75bfc23d7406
  ... 0xbacb020810d5859bd911aec131147b03ab9529ce2ac1968fa0b5774367443aaf
  ... 0x9f0b1fa6ad57ca8a7b5373c3fce0b30576a0d522f8eefac44f4755c7d9adc166
  ... 0x5f79133f5973ad46c9ed3edbced7f6b71d6ca39ad1e39fd862cd411227d35a22
  ... 0xf501f0ced5dc35aae7745b837181a9d2693167673433c2ce9d3bdb10edfe451c
  ... 0x265e69d23ad9423a631b95bf159599277db7afd4901b107f22652b1bd2fb2260
  ... 0xd70e1e0da2f7bed7a00a98e41dafb661be409872315e4bb3c293b4845163fdd0
Saving artifacts...
Running migration: 7_initialize_trading.js
Saving successful migration to network...
  BCoin: 0x8273e4b8ed6c78e252a9fca5563adfcc75c91b2a
  ACoin: 0xcfed223fab2a41b5a5a5f9aaae2d1e882cb6fe2d
  CCoin: 0x8273e4b8ed6c78e252a9fca5563adfcc75c91b2a
  DCoin: 0xf08df3efdd854fede77ed3b2e515090eee765154
  ICoin: 0x2467636bea0f3c2441227eedbffac59f11d54a80
  ECoin: 0x74e3fc764c2474f25369b9d021b7f92e8441a2dc
  Dummy: 0x855d1c79ad3fb086d516554dc7187e3fdfc1c79a
  GCoin: 0x8e4c131b37383e431b9cd0635d3cf9f3f628edae
  FCoin: 0x98d9f9e8debd4a632682ba207670d2a5acd3c489
  HCoin: 0x1411cb266fced1587b0aa29e9d5a9ef3db64a9c5
  ... 0xfef5e8867f8d767787de748407765993eb2bbb5e2bc9ba54c1ab27dd99d2e56a
Saving artifacts...

Migrations 6 and 7 are both empty.

Error: Dummy has not been deployed to detected network (network/artifact mismatch)
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:317898:17

Environment

  • Operating System: Ubuntu 17.10 uname -a
Linux fiskens-dator 4.13.0-25-generic #29-Ubuntu SMP Mon Jan 8 21:14:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Truffle version: v4.0.5
  • Ethereum client: ganache-1.0.1 (No client installed so far, just a local testnet)
  • node version: v9.4.0
  • npm version: 5.6.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
cgeweckecommented, Jan 25, 2018

@terraflops Thanks so much for making a simple demo of this! Really appreciate it.

I’ve gotten the migrations to populate the network object as expected by removing the deployed promise from the migrations files for derived contracts and passing the deployer the artifact address directly: ex:

var Derived1 = artifacts.require("Derived1");
var Data = artifacts.require("Data");
module.exports = function(deployer) {

    /* --- Original ---
    Data.deployed().then(function(instance) {
         deployer.deploy(Derived1, instance.address);
    });*/

    // --- New ---
    deployer.deploy(Derived1, Data.address);
}

The behavior of promises in the migrations is a topic that should probably be expanded on in the docs - apologies for this - FWIW there’s an example of an issue similar to yours here.

Migrations stage deployments rather than executing them immediately, so if you want to execute code asynchronously (like Data.deployed) that’s something which has to be returned as a promise to the deployer. For your case the following should also work:

module.exports = function(deployer) {
    deployer.then(function(){
      return Data.deployed();
    }).then(function(instance){
      return deployer.deploy(Derived1, instance.address)
    });
}
0reactions
elie222commented, Mar 11, 2018

Can confirm this rewrite worked for me too. But seems like a bug in Truffle that things should be done this way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

contract not deployed to detected network - Ethereum Stack ...
I'm having a problem deploying multiple contracts. The first address gets written in contract1.json but contract2.json isn't showing an ...
Read more >
Interacting with Deployed Ethereum Contracts in Truffle
“myContract.deployed()” returns an instance of the deployed promise MyContract object, meaning that the deployed address is known and recorded in the json file...
Read more >
Deploy & Run — Remix - Ethereum IDE 1 documentation
json file to customize the playback. Deploying contract does often require more than creating one transaction and so the recorder will automate this...
Read more >
Compiling your contracts | Ethereum development ... - Hardhat
If you only modified one file, only that file and others affected by it will be recompiled. To force a compilation you can...
Read more >
Truffle Migrations Explained - SitePoint
These *.json files contain descriptions of their respective smart ... Not only do migrations allow us to deploy multiple contracts with a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found