Not sure if this is still relevant, but I am going to leave this here for future generations.
I've been struggling to deploy with truffle + Infura on mainnet a lot lately. One and the same script seems to work on testnet (ropsten, rinkeby) and not work on mainnet. It fails especially miserably when performing transactions outside of the standard deployer.deploy(contract, params)
(Much like what you do with instance.createListing()
).
I've narrowed this down partially to web3.js (transactions were hanging or not being sent) and partially to truffles embedded setCompleted
transaction being called all the time (causing nonce problems with Infura).
Firstly I tried using ethers.js
in the migrations scripts and it improved a lot the things especially with the hanging transactions. However, I lost all the verboseness and the setCompleted
stuff still caused a lot of trouble. I've moved to my own deployment scripts since then. I basically write a script like this and run it using node:
const etherlime = require('etherlime');
const ProductionFactory = require('./testContracts/ProductionFactory');
const ProductionFactoryProxy = require('./testContracts/ProductionFactoryProxy');
const IProductionFactory = require('./testContracts/IProductionFactory');
const defaultConfigs = {
gasPrice: 20000000000, // Choose your configs wisely
gasLimit: 4700000
}
const deployer = new etherlime.InfuraPrivateKeyDeployer('Your Private Key Here', 'ropsten', 'Your Infura Key', defaultConfigs);
const runUpgradeableFactory = async () => {
const productionFactoryWrapper = await deployer.deploy(ProductionFactory);
const proxyWrapper = await deployer.deploy(ProductionFactoryProxy, productionFactoryWrapper.contractAddress);
const upgradeableFactoryWrapper = deployer.wrapDeployedContract(IProductionFactory, proxyWrapper.contractAddress);
const initTransaction = await upgradeableFactoryWrapper.contract.init(randomAddress, defaultConfigs);
const result = await upgradeableFactoryWrapper.verboseWaitForTransaction(initTransaction.hash, 'Init Factory');
}
runUpgradeableFactory();
P.S. I've since developed the handy tool etherlime to help me with verboseness.
web3.eth.getTransacctionCount(address, "pending")
) and manually increment in your loop and pass it as parameter to createListing. This way you can exactly specify the order in which transactions should be processed. – ivicaa Mar 31 '18 at 4:33