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?

3
  • do not see a reason, and your embarassment is justified. Jul 9, 2016 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. Jul 9, 2016 at 21:12

1 Answer 1

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.

1
  • 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, 2016 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.