Commit 5f93ea16 authored by d11e9's avatar d11e9

Tidy nodejs/npm usage

parent cf97d6dd
...@@ -3,13 +3,16 @@ ...@@ -3,13 +3,16 @@
Browser solidity is a browser based solidity compiler. To use either visit https://chriseth.github.io/browser-solidity or clone/download this repo and open `index.html` in your browser. Browser solidity is a browser based solidity compiler. To use either visit https://chriseth.github.io/browser-solidity or clone/download this repo and open `index.html` in your browser.
#Solidity compiler #Nodejs usage
To use the solidity compiler via nodejs you can do the following: To use the solidity compiler via nodejs you can install it via npm
npm install --save solc
And then use it like so:
var solc = require('solc'); var solc = require('solc');
var compileJSON = solc.cwrap("compileJSON", "string", ["string", "number"]);
var input = "contract x { function g() {} }"; var input = "contract x { function g() {} }";
var output = JSON.parse(compileJSON(input, 1)); // 1 activates the optimiser var output = solc.compile(input, 1); // 1 activates the optimiser
for (var contractName in output.contracts) for (var contractName in output.contracts)
console.log(contractName + ': ' + output.contracts[contractName].bytecode); console.log(contractName + ': ' + output.contracts[contractName].bytecode);
\ No newline at end of file
var soljson = require('./bin/soljson-latest.js');
compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]);
module.exports = {
compile: function(input, optimise){
return JSON.parse( compileJSON(input, optimise) );
}
}
\ No newline at end of file
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
"name": "solc", "name": "solc",
"version": "0.1.3", "version": "0.1.3",
"description": "Solidity compiler", "description": "Solidity compiler",
"main": "soljson-latest.js", "main": "index.js",
"bin": { "bin": {
"solc": "soljson-latest.js" "solc": "bin/soljson-latest.js"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment