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

Deploy on Ropsten fails but no message explaining why #974

Closed
1 task done
rmi7 opened this issue May 30, 2018 · 10 comments
Closed
1 task done

Deploy on Ropsten fails but no message explaining why #974

rmi7 opened this issue May 30, 2018 · 10 comments

Comments

@rmi7
Copy link

rmi7 commented May 30, 2018


Issue

so I’m deploying 3 contracts (+ Migrations.sol) on both ganache locally AND —dry-run on ropsten. both giving me the below output for deployment of the last contract of the 4:

Running migration: 4_deploy_MyMagicalContract.js
Saving successful migration to network...
  ... 0x9609a386fc40ac5245137a352e8c8982e68a4ab20568921bd52bfa2241e5c86d
  Deploying MyMagicalContract...
Saving artifacts...
  ... 0xd869cdfaf31256f873fa573454c852b3ba24816f30b148df30914fd10756c94f
  MyMagicalContract: 0xcb7109f76e9da709c940fdda378211c9856e16fb
  ... 0x676b922b9fff07deb9c5c468f88820a55406c715799a05e007b046167856fbd4
  ... 0x9149a825552b2b84da23d728f5b5bf43f3b91c4a9a2d4b4db13a13393dc6400b

but when I actually deploy on ropsten (so no dry run) I only get this for the last contract:

Running migration: 4_deploy_MyMagicalContract.js
Saving successful migration to network...
  Deploying MyMagicalContract...
  ... 0x8a25b59f32d78ca108dedb93e7173db9855b2691a884eb4052d999cddb71d5d2
  ... 0x082a3ebedd92bae28e00a9a3476f5f67b31ad8779c01e0c15b1b66ba54247297
Saving artifacts...

Expected Behavior

Expected either:

  • a successful deploy of MyMagicalContract.sol
  • an indication/error of why it won't deploy MyMagicalContract.sol

Actual Results

  • no deploy of MyMagicalContract.sol
  • no message explaining why it won't deploy MyMagicalContract.sol

Environment

  • Operating System: Mac OS
  • Ethereum client: Infura
  • Truffle version 4.1.11
  • node version 8.9.4
  • npm version 5.6.0
@cgewecke
Copy link
Contributor

cgewecke commented May 30, 2018

@rmi7 Is this your contract deployed to Ropsten at tx 0x082a3ebedd92bae28e00a9a3476f5f67b31ad8779c01e0c15b1b66ba54247297 ?

Could you look at the artifacts for MyMagicalContract and see if there is an address saved under the networks key for the Ropsten network?

Looks like it should be: 0x8a5fa2e6035fb19880a54f4f974d1ef320290988

@rmi7
Copy link
Author

rmi7 commented May 30, 2018

Looks like it yes,

and no, there is no update to the networks: of that file,

for all other migrations before this one there is an update to the networks section in their json file.

are there any specific things that I could be doing inside a migration file which would prevent the networks section to update?

UPDATE verified that that is indeed my contract, verified and added source code, still leaves the question why network is not updated and no output in truffle migration log

@michaeljohnbennett
Copy link
Contributor

I'm getting the same kind of timeout

it seems it does update my version but still get a timeout.

My Versions:

Truffle v4.1.8 (core: 4.1.8)
Solidity v0.4.23 (solc-js)
[email protected]

@cgewecke
Copy link
Contributor

@michaeljohnbennett The timeout problem should be fixed in 4.1.11 - recent changes to a dependency in the wallet provider resulted in commands failing to exit correctly. As a side note - it's now important that you wrap providers in a function in truffle.js if you've configured more than one network in your config. See example here

@rmi7 Can you share your migrations.js and truffle.js? It's possible there's a promise you're not returning to the deployer at the very end of the sequence.

@michaeljohnbennett
Copy link
Contributor

I cleaned out node_modules and did a reinstall of 4.1.11 and it works. Also globally.

I am using the lazy initialisation functions for wallet provider functions.

You should have that changed on master branch docs as well as its confusing all the variations on this piece caused me a lot of hassle at the beginning.

Thanks so much for you help.

@cgewecke
Copy link
Contributor

Ah ok! Thanks for the tip about the docs, will check that out.

@rmi7
Copy link
Author

rmi7 commented May 31, 2018

MyMagicContract.sol == ICO.sol below

that didn't fix it for me, still working on ganache + ropsten dry run, but not actual deploy on ropsten, the last migration is the below, the other two contracts I require have been successfully deployed (their networks: {} is updated correct in their JSON file) in a separate migration before this one.

Result =
the migration console output in the main issue text at the top of this page
+
not getting an updated networks: {} section inside ICO.json
the only update in ICO.sol is the updatedAt value
+
this statement is not executed: console.log('DEPLOYED ICO', ICO.address, (await ICO.deployed()).address);

Last Migration

const ICO = artifacts.require('./ICO.sol');
const MyToken = artifacts.require('./MyToken.sol');
const Membership = artifacts.require('./Membership.sol');

const UnixTimestamp = jsTimestamp => (
  Math.floor(jsTimestamp / 1000)
);

module.exports = async (deployer, network, accounts) => {
  // get already deployed MyToken + Membership contracts
  const token = await MyToken.deployed();
  const member = await Membership.deployed();

  // constructor args for Ico contract
  const rate = 3000;               
  const token = token.address;       
  const tokenWallet = accounts[0]; 
  const membership = member.address;
  let ethWallet;
  let startTime;
  let endTime;

  if (network === 'mainnet') {
    // ETH wallet is separate address
    if (!process.env.ETH_WALLET_ADDRESS) {
      throw new Error('need ETH_WALLET_ADDRESS env var to be set');
    }
    if (!web3.isAddress(process.env.ETH_WALLET_ADDRESS)) {
      throw new Error(`env var ETH_WALLET_ADDRESS is not a vlid ETH address, value: ${process.env.ETH_WALLET_ADDRESS}`);
    }
    ethWallet = process.env.ETH_WALLET_ADDRESS;

    startTime = 1529146400; 
    endTime   = 1535264399; 
  } else {
    ethWallet = accounts[0];

    startTime = UnixTimestamp(Date.now() + 60 * 1000 * 5); // 5 minutes from now
    endTime = UnixTimestamp(Date.now() + 60 * 1000 * 60 * 24 * 14); // 14 days
  }

  // deploy Ico contract --> GAS USED: 2,291,944
  await deployer.deploy(ICO, startTime, endTime, rate, ethWallet, token, tokenWallet, membership);
  
  console.log('DEPLOYED ICO', ICO.address, (await ICO.deployed()).address);
  const ico = await ICO.deployed();
  
  // allow Ico contract to add members to membership contract
  await member.addAdmin(ico.address);
  
  // get the max amount of tokens that this Ico contract will sell
  // we can later update this to be even bigger if the need arises, using another token.approve from remix
  const MAX_ICO_TOKENS = 14625000; // 19000000 + 150% of 19000000;                                      
  
  // allow Ico contract to transfer MAX_ICO_TOKENS NTS tokens
  await token.approve(ico.address, web3.toWei(MAX_ICO_TOKENS))
};

truffle.js

const assert = require('assert');
const HDWalletProvider = require("truffle-hdwallet-provider");

require('dotenv').config({ path: require('path').join(__dirname, '.env') });

assert(process.env.INFURA_API_TOKEN, 'missing INFURA_API_TOKEN in .env file');
assert(process.env.HD_WALLET_MNEMONIC, 'missing HD_WALLET_MNEMONIC in .env file');

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    ropsten: {
      provider: () => new HDWalletProvider(
        process.env.HD_WALLET_MNEMONIC,
        `https://ropsten.infura.io/${process.env.INFURA_API_TOKEN}`,
      ),
      gas: 4700000,
      gasPrice: 17e9,
      network_id: 3,
    },
    mainnet: {
      provider: () => new HDWalletProvider(
        process.env.HD_WALLET_MNEMONIC,
        `https://mainnet.infura.io/${process.env.INFURA_API_TOKEN}`,
      ),
      gas: 5e6, // 5 million
      gasPrice: 10e9, // 10 gwei
      network_id: 1,
    },
  },
};

@cgewecke
Copy link
Contributor

@rmi7 Believe the problem is with async/await which Migrations only supports if it's wrapped in a deployer.then block. Apologies for this - Migrations was written before async/await became the norm and 'stages' deployments with it's own promise chain management logic. (We're in the middle of rewriting that module so this shouldn't be an issue in a few weeks.)

TLDR; everything should work if you wrap your async/await migrations logic like this:

module.exports = function(deployer, network, accounts) {
  deployer.then(async function(){
     ... all your setup / deploys / etc
   })

There's a nice example of this here and the issue is being tracked at #501.

@rmi7
Copy link
Author

rmi7 commented May 31, 2018

thanks @cgewecke, amazing that does it!!!

🎇😎☄️

@rmi7
Copy link
Author

rmi7 commented Jun 4, 2018

also relevant: trufflesuite/truffle-migrate#29 (comment)

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

3 participants