Mist / Ethereum Wallet now has a built-in compiler that is not very well documented beyond screenshots in the tutorials in order to create, compile, and deploy contracts. However, the version of Mist's compiler and whether or not it is optimized is...hard to figure out.
However, this does NOT necessarily solve your problem with getting verified on EtherScan. I cannot get the token code to match either, no matter what I tried (and I tried a lot). See the bottom of this comment if you want to dive in with me.
If getting verified on EtherScan is important to you, then write your Solidity code wherever but compile it using Browser Solidity here: http://chriseth.github.io/browser-solidity/
Then use that bytecode to deploy. I have not tested it but the code it spits out for the sample token contract matches what EtherScan spits out. I assume that EtherScan is using that same browser-based compiler to check and verify contracts.
If you are using Mix IDE / Solidity, you can view the Solidity version by going (in the Mix IDE) to File/Mix/Help - > About.
If you are using solc / Solidity (command line interface) you can use the command web3.eth.compile
which will then spit out something like:
contract = eth.compile.solidity(source).test
{
code: '605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056',
info: {
language: 'Solidity',
languageVersion: '0',
compilerVersion: '0.9.13',
abiDefinition: [{
constant: false,
inputs: [{
name: 'a',
type: 'uint256'
} ],
name: 'multiply',
outputs: [{
name: 'd',
type: 'uint256'
} ],
type: 'function'
} ],
userDoc: {
methods: {
}
},
developerDoc: {
methods: {
}
},
source: 'contract test { function multiply(uint a) returns(uint d) { return a * 7; } }'
}
}
This will compile your code and give you information like compiler version, etc.
More Information
Optimization is a choice you can make. Via solc, you use the --optimize
flag. You can read more about this magical optimization property here:
How does the solidity optimizer work?. I think Mist is optimizing based on the fact that I had a 73% similarity when I chose "not optimized" on EtherScan and a 93% similarity when I chose optimized.
Contract Testing:
I have created the exact contract https://www.ethereum.org/token#the-code with no change whatsoever to the code using Mist v 0.5.2.
The contract code that Etherscan.io received / Mist sent was:
0x6060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056
You can see this on EtherScan, or you can get it in Ethereum Wallet by opening the console and running TokenContract.eth.getCode('YOUR_ADDRESS_HERE_NO_0x_AT_BEGINNING');
Both Mist and EtherScan spit out the same code.
I attempted to verify maybe 20 different versions, with and without optimization, using Browser Solidity and never once is that code as short or Etherscan.io has it, nor does it start with 0x.....
Here is an example of what Browser Solidity & EtherScan give me using 0.2.1-3ad5e821 w/ optimization:
606060405260405161092b38038061092b83398101604052805160805160a05160c05160e05193949283019391929081019101600160a060020a03331660009081526005602090815260408220879055600487905581548651838052601f6002600019600185161561010002019093169290920482018390047f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390810193919290918901908390106100d457805160ff19168380011785555b506101049291505b8082111561015d57600081556001016100c0565b828001600101855582156100b8579182015b828111156100b85782518260005055916020019190600101906100e6565b50508160016000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061016157805160ff19168380011785555b506101919291506100c0565b5090565b82800160010185558215610151579182015b82811115610151578251826000505591602001919060010190610173565b50506003805460ff19168417905560028054825160008390527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace602060018416156101000260001901909316849004601f90810184900482019386019083901061020e57805160ff19168380011785555b5061023e9291506100c0565b82800160010185558215610202579182015b82811115610202578251826000505591602001919060010190610220565b505050505050506106d8806102536000396000f36060604052361561008d5760e060020a600035046306fdde03811461009557806318160ddd146100f257806323b872dd146100fb578063313ce5671461012d57806354fd4d501461013957806370a082311461019357806395d89b41146101ab578063a9059cbb14610207578063cae9ca5114610236578063dc3080f214610398578063dd62ed3e146103bd575b6103e2610002565b6103e460008054602060026001831615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260045481565b610452600435602435604435600160a060020a0383166000908152600560205260408120548290101561057057610002565b61046460035460ff1681565b6103e460028054602060018216156101000260001901909116829004601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b61045260043560056020526000908152604090205481565b6103e4600180546020600282841615610100026000190190921691909104601f810182900490910260809081016040526060828152929190828280156104995780601f1061046e57610100808354040283529160200191610499565b6103e2600435602435600160a060020a033316600090815260056020526040902054819010156104a157610002565b60806020604435600481810135601f810184900490930284016040526060838152610452948235946024803595606494939101919081908382808284375094965050505050505060006000836006600050600033600160a060020a03168152602001908152602001600020600050600087600160a060020a031681526020019081526020016000206000508190555084905080600160a060020a0316638f4ffcb1338630876040518560e060020a0281526004018085600160a060020a0316815260200184815260200183600160a060020a03168152602001806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561036b5780820380516001836020036101000a031916815260200191505b50955050505050506000604051808303816000876161da5a03f11561000257506001979650505050505050565b6007602090815260043560009081526040808220909252602435815220546104529081565b6006602090815260043560009081526040808220909252602435815220546104529081565b005b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f1680156104445780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60408051918252519081900360200190f35b6060908152602090f35b820191906000526020600020905b81548152906001019060200180831161047c57829003601f168201915b505050505081565b600160a060020a0382166000908152604090205480820110156104c357610002565b806005600050600033600160a060020a03168152602001908152602001600020600082828250540392505081905550806005600050600084600160a060020a0316815260200190815260200160002060008282825054019250508190555081600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a35050565b600160a060020a03831681526040812054808301101561058f57610002565b600160a060020a038085168083526006602090815260408085203394909416808652938252808520549285526007825280852093855292905290822054830111156105d957610002565b816005600050600086600160a060020a03168152602001908152602001600020600082828250540392505081905550816005600050600085600160a060020a03168152602001908152602001600020600082828250540192505081905550816007600050600086600160a060020a03168152602001908152602001600020600050600033600160a060020a0316815260200190815260200160002060008282825054019250508190555082600160a060020a031684600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3506001939250505056
So....it still doesn't match what Mist supposedly sent and EtherScan received.
While doing research, I found that EtherChain may have better luck with verification. I, however, still could not get anything above ~93% similarity (using 2.1.1, optimized).
Hope this helps someone.
Best Answer
The optimizer seems like magic even to me. chriseth (He is the main DEV developer of solidity) would probably be in a better position to answer your question than myself. Here is an interesting high level overview though, which I hope answers your question.
Everything below is from the solidity docs.