I am trying to deploy my smart contract with truffle and an Infura HDWalletProvider. Here's my dry run (I edited/shortened it for brevity):
Migrations dry-run (simulation)
===============================
> Network name: 'live-fork'
> Network id: 1
> Block gas limit: 29999802 (0x1c9c2ba)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> account: <hidden>
> balance: 0.365066926
> gas used: 138922 (0x21eaa)
> gas price: 32 gwei
> value sent: 0 ETH
> total cost: 0.004445504 ETH
-------------------------------------
> Total cost: 0.004445504 ETH
2_deploy_contracts.js
=====================
Deploying 'MyFirstContract'
-------------------------
> account: <hidden>
> balance: 0.131909166
> gas used: 7258890 (0x6ec30a)
> gas price: 32 gwei
> value sent: 0 ETH
> total cost: 0.23228448 ETH
Adding the two migrations gas units up, I get 7397812
units of gas.
and my truffle config:
live: {
network_id: 1,
provider: () => new HDWalletProvider(privatekey, infuraUrl),
gasPrice: web3.utils.toWei('32', 'gwei'),
gas: 7500000,
// skipDryRun: true
}
I have set the gas
to be just higher than the 7397812
units.
I'm trying to understand a couple things, so I don't lose ETH in a failed transaction. Full disclosure, I just lost 1/3 of an ETH because my settings were wrong. ("Migrations" ran out of gas (using a value you set in your network config or deployment parameters.))
- Do I need to set the
gas
value? Is this just a ceiling, to prevent me spending too much? - Can I count on the
7397812
units from the dry run? Will this be the same number of units during the live deploy, or is there potentially more gas units I'll need to account for? - Why is the balance under
2_deploy_contracts.js
not the same as the balance under1_initial_migration.js
. At the very least, I would expect it to be the difference between the 1st migrations balance and it's total cost (0.365066926-0.004445504
), but it is not. - Most importantly: given funds in my wallet and the
gasPrice
andgas
settings intruffle-config.js
, how can I ensure that the settings protect me from losing ETH in the migration, by failing before the transaction is created?
The price of gas fluctuates wildly and I want to reduce my costs by setting a mid-to-low range gas price, but not at the expense of losing all my gas in a failed transaction.