diff --git a/README.md b/README.md index a83f0a988f..14ea9e2ae9 100644 --- a/README.md +++ b/README.md @@ -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. -#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 compileJSON = solc.cwrap("compileJSON", "string", ["string", "number"]); 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) console.log(contractName + ': ' + output.contracts[contractName].bytecode); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000000..8b516b3bb4 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ + +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 diff --git a/package.json b/package.json index 48c8497881..c516420b7a 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "solc", "version": "0.1.3", "description": "Solidity compiler", - "main": "soljson-latest.js", + "main": "index.js", "bin": { - "solc": "soljson-latest.js" + "solc": "bin/soljson-latest.js" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1"