Skip to content

Instantly share code, notes, and snippets.

@agatsoh
Created February 5, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agatsoh/9e1241b38e0f40af0a76 to your computer and use it in GitHub Desktop.
Save agatsoh/9e1241b38e0f40af0a76 to your computer and use it in GitHub Desktop.
var solc = require('solc');
var fs = require('fs');
var Web3 = require('web3');
const assert = require('assert');
var web3;
if(typeof web3 !== 'undefined')
web3 = new Web3(web3.currentProvider);
else
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:4000/"));
var input = { "IOU.sol":fs.readFileSync('contracts/IOU.sol','utf8'),
"Fund.sol":fs.readFileSync('contracts/Fund.sol','utf8'),
"RootRegistry.sol":fs.readFileSync('contracts/RootRegistry.sol','utf8'),
"Gateway.sol":fs.readFileSync('contracts/Gateway.sol','utf8')
};
var output = solc.compile({sources:input},1);
for (var contractName in output.contracts){
deployContract(contractName,output.contracts[contractName]);
}
function deployContract(contractName,contractJSONObject)
{
var contractObj = web3.eth.contract(contractJSONObject.interface);
//console.log(contractObj.abi);
var contractNew = contractObj.new(
{
from: web3.eth.accounts[0],
data:contractJSONObject.bytecode,
gas:3000000
}, function(e, contract){
console.log(contract.transactionHash);
});
}
@agatsoh
Copy link
Author

agatsoh commented Feb 5, 2016

var solc = require('solc');
var fs = require('fs');
var Web3 = require('web3');
const assert = require('assert');
var web3;
if(typeof web3 !== 'undefined')
web3 = new Web3(web3.currentProvider);
else
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:4000/"));

var input = { "IOU.sol":fs.readFileSync('contracts/IOU.sol','utf8'),
"Fund.sol":fs.readFileSync('contracts/Fund.sol','utf8'),
"RootRegistry.sol":fs.readFileSync('contracts/RootRegistry.sol','utf8'),
"Gateway.sol":fs.readFileSync('contracts/Gateway.sol','utf8')
};

var output = solc.compile({sources:input},1);
//console.log(output);
for (var contractName in output.contracts){

deployContract(contractName,output.contracts[contractName]);

}

function deployContract(contractName,contractJSONObject)
{
//console.log(typeof contractJSONObject.interface);
//console.log(typeof JSON.parse(contractJSONObject.interface));
var contractObj = web3.eth.contract(JSON.parse(contractJSONObject.interface));
//console.log(contractObj.abi);

var contractNew =  contractObj.new(
    {
        from: web3.eth.accounts[0],
        data:contractJSONObject.bytecode.toString(),
        gas:3000000
    }, function(e, contract){
console.log(contract.transactionHash);
});

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment