r/EthereumProgramming • u/RudimentaryDorsalFin • Jun 12 '16
Creating contract from text file
Working on my first ethereum contracts, trying to find a nice way to work with files and consoles. I cannot find a convenient way to import contract code text into some variable in console to compile it.
After coding something, I have a .sol file. Then there are several ways to go:
- Copy the content as text and assign it to the variable in console. Not nice, and one needs to remove/escape newlines.
- Convert the .sol file into .js file that takes the text of your contract and assigns it to the variable. Then, you can do loadScript('my_contract_as_js_string.js')
- Attach a node.js console, load web3 and use an HttpProvider. This is a nice way to load and compile the contract. But I cannot instantiate it because I need to unlock my account first. So I have to attach a console to my node in another terminal and unlock accounts there. I perfectly understand the reason it cannot be done via RPC.
All three methods are crap (except for the last one, it's just ugly). I have a strong feeling that I've overlooked some simple and trivial solution. Is there one?
Loading a js script that is doing require('fs') is not going to work.
4
Upvotes
View all comments
Show parent comment
1
u/RudimentaryDorsalFin Jun 15 '16
This is exactly an advice I was looking for. Made simple js scripts with web3 and solc npm modules for compilation.