Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

'truffle compile' doesn't work properly when using multiple network providers. #962

Closed
gerchicov-bp opened this issue May 23, 2018 · 6 comments

Comments

@gerchicov-bp
Copy link

Issue

Used truffle 4.1.8 and everything was ok. Updated to the latest (4.1.11). Now it seems it compiles the contracts but I must cancel/stop it manually. Here is my folder:
http://dropmefiles.com/7dHdO
In the same time tried to compile contracts in another folder - it compiles them successfully.

Steps to Reproduce

Unzip the folder from this link and run truffle compile.

Expected Behavior

Compiling process is finished successfully

Actual Results

It seems that contracts are compiled but I see Writing artifacts to ./build/contracts infinitely.

Environment

  • Operating System: OSX 10.13.4
  • Ethereum client: none (is not involved)
  • Truffle version (truffle version): 4.1.11
  • node version (node --version): v9.9.0
  • npm version (npm --version): 6.0.1
@gerchicov-bp gerchicov-bp changed the title truffle compile doesn't work properly 'truffle compile' doesn't work properly May 23, 2018
@cgewecke
Copy link
Contributor

cgewecke commented May 23, 2018

Will check this out in few minutes (on a train) but our CI is passing and have manually verified that commands are completing ok on MetaCoin. Why is it working in one folder for you and not in another?

@cgewecke
Copy link
Contributor

@gerchicov-bp I'm getting your project to compile ok after wrapping the wallet providers in functions, as suggested by the docs here. Have only tried with the localhost network I stubbed in. Could you double-check that your custom host is working?

truffle.js

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  networks: {

    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*" // Match any network id
    },
    /*},
    development: {
      host: "<custom-host>",
      port: 8545,
      network_id: "*"
    },*/
    rinkeby: {
      provider: function() {
        return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/<infura-key>");
      },
      gas: 4500000,
      gasPrice: 25000000000,
      network_id: 4
    },
    ropsten: {
      provider: function() {
        new HDWalletProvider(mnemonic, "https://ropsten.infura.io/<infura-key>");
      },
      gas: 4500000,
      gasPrice: 25000000000,
      network_id: 3
    }
  }
};

Output

gerchicov user$ truffle version
Truffle v4.1.11 (core: 4.1.11)
Solidity v0.4.24 (solc-js)
gewecke:gerchicov user$ truffle compile
Compiling ./contracts/ClientReceipt.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/Simple.sol...

Compilation warnings encountered:

/gerchicov/contracts/Migrations.sol:11:3: Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
  function Migrations() public {
  ^ (Relevant source part starts here and spans across multiple lines).
,/gerchicov/contracts/Simple.sol:6:3: Warning: No visibility specified. Defaulting to "public". 
  function getA() constant returns (uint256) {
  ^ (Relevant source part starts here and spans across multiple lines).
,/gerchicov/contracts/Simple.sol:10:3: Warning: No visibility specified. Defaulting to "public". 
  function setA(uint256 newValue) {
  ^ (Relevant source part starts here and spans across multiple lines).

Writing artifacts to ./build/contracts

gerchicov user$ 

@cgewecke cgewecke changed the title 'truffle compile' doesn't work properly 'truffle compile' doesn't work properly when using multiple network providers. May 23, 2018
@Gargo
Copy link

Gargo commented May 23, 2018

@cgewecke Yes, your code works. BUT:
1)what is the difference and why does my format is mentioned in the documentation as correct too?
2)how and why settings for "migration" influence "compilation"?

@cgewecke
Copy link
Contributor

@Gargo

  1. Unfortunately the non-function format for the wallet is only reliable if there is a single provider. The docs could use some improvement in that section because it's not obvious why there are two formats. The 'function' form was introduced because the non-function form causes super weird behavior in the provider when there are multiple connections open to Infura. Original bug report at RPC providers unnecessarily initialize in different environments #348.

  2. No great answer for this - truffle compile builds the artifacts and networks are one the things we track in that object. At the moment this isn't very helpful but it will become important when the artifact is refactored for the next major release because it will be possible to specify different compilations for different networks. In the comment above I'm just trying to narrow things a bit so we can figure out what's going wrong. I know the config is getting loaded - I want to see if there's a specific issue with connecting remotely or not.

@emin93
Copy link

emin93 commented May 24, 2018

Thanks @cgewecke, for me that was the missing part. As soon as I switched to the "function" form, the issue got resolved.

  • Truffle version (truffle version): Truffle v4.1.11 (core: 4.1.11) Solidity v0.4.24 (solc-js)
  • Node version (node -v): v8.11.2
  • NPM version (npm -v): 6.0.1
const path = require("path");
const HDWalletProvider = require("truffle-hdwallet-provider");

module.exports = {
  contracts_build_directory: path.join(process.cwd(), "src/Contracts"),
  networks: {
    mainnet: {
      provider: () => new HDWalletProvider(mnemonic, "https://mainnet.infura.io/<infura-key>"),
      network_id: 1
    },
    rinkeby: {
      provider: () => new HDWalletProvider(, "https://rinkeby.infura.io/<infura-key>"),
      network_id: 4
    }
  }
};

@cgewecke
Copy link
Contributor

@gerchicov-bp Thanks for opening this - have amended the docs to remove the non-function closure examples.

Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants