2

web3.eth.compile.solidity ask for a string as a parameter. Not only, it must be a string without line breaks: in the official greeter tutorial to use an online-tool to remove line breaks from contract is encouraged.

I find that very embarrassing, and I feel that the typical signature for such a method should get a path to a .sol file instead of a string. So... maybe web3 not compiling from a file is some sort of security measure? Or there is any powerful reason to web3 not compiling from a source file I'm unaware?

Sergeon
  • 396
  • 1
  • 8
  • Related: https://ethereum.stackexchange.com/questions/3645/how-to-compile-sol-file-from-the-command-line – Richard Horrocks Jul 09 '16 at 20:25
  • do not see a reason, and your embarassment is justified. – Roland Kofler Jul 09 '16 at 20:42
  • All I can think of is you'd generally not normally run Javascript code from a command line, but rather as a script. In a script, having your contract code as a variable allows it to be easily manipulated (or created from scratch). In such cases, having to write the code to a file before compiling is just an extra step. – Richard Horrocks Jul 09 '16 at 21:12

1 Answers1

1

web3 may be used directly inside the browser (i.e. in a dapp), in which case there's no access to the filesystem anyway. Requiring actual direct code allows in-browser use of web3.eth.compile, and console JS systems (i.e. node) have their own methods of reading the filesystem.

Matthew Schmidt
  • 7,290
  • 1
  • 24
  • 35
  • Yeah I guess web3.js being designed mainly to client side scripting instead than for nodejs is the main reason for that. But I use to deploy contracts and test things with node and have to compile in the console with solc and then do stuff is some sort of a pain in the ass. Btw is someone is reading this bc is having problems to deploy contract with web3, I strongly suggest to use Pudding instead of vanilla web3 contract. – Sergeon Jul 10 '16 at 17:03