The calculation is gas
*gascost
, so a simple transaction will cost 21,000 gas * 20 GWei/gas = .00042 ETH
I can reproduce this with compiler version 0.4.12+commit.194ff033.Emscripten.clang (but, in my case, the other way round - file1.sol has a deployment cost of 68990, file2.sol has a deployment cost of 68926.)
There is a 64 gas difference in the cost between the two deployments. The reason for this is that, although the deployment code is exactly the same length (82 bytes), one of the sets of bytecodes has a zero byte in a place where the other has a non-zero byte.
When transmitting a transaction to the blockchain, the gas cost per byte of calldata is 68 for non-zero bytes, and 4 for zero bytes (Appendix G of the Yellow paper, G_txdatanonzero vs. G_txdatazero). Hence the 68 - 4 = 64 gas difference between your codes.
The different byte actually occurs in the appended contract metadata section, not in the deployment code or the deployed code itself which are identical for both your examples as you would expect. The following are the metadata sections for the contracts - the metadata is generated automatically by the compiler and comprises a Swarm hash of the contents of the source file plus some other bits and pieces:
a165627a7a72305820176535c2c0a4a3ac4a26111bf3f9aa4ab0fa5db14d592f8574bf15f1f42f46420029
a165627a7a723058204e0a27613ab151031db65041c0e2ff84bf88842fd7b2cc00163bc9af9acd05230029
zero/non-zero byte difference is here ^^
So, with two near identical source files you have some chance of there being a difference in deployment cost due to this, and it is compiler version dependent since the compiler version is embedded in the data used to create the Swarm hash.
Best Answer
The Mist wallet will be connecting to a local Ethereum protocol implementation, commonly Geth. Mist connects to Geth via
Web3.js
and transaction fees are relayed back to your Mist wallet depending on how you client implementation calculated it.Mist would be using the estimateGas API to help with its calculations:
And we know that transaction fees are calculated as:
Basically, Mist would be executing something similar to this:
You can find the exact source code from the Mist project that calculates this here.
To understand transaction fees in more detail: please refer to this question.
Finally, you're probably seeing these fluctuations in transaction costs because of the wide range of gas prices on the network set by miners on the network. Right now, it costs very little to get your transaction mined, see here. If the miners decrease their
gasPrice
to include more transactions then they'll see an increase in orphan rate. The cost of getting orphaned is denominated in ETH, so the gas price miners are willing to accept should go up as the ETH price does.Hope this helps.