Created
February 24, 2018 22:41
-
-
Save AbstractFruitFactory/e5975367bc77494940cc955f1061b962 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3'); | |
const solc = require('solc'); | |
const fs = require('fs'); | |
var LineReader = require('linereader'); | |
var lr = new LineReader('sampledata.txt'); | |
const BATCH_SIZE = 3; | |
function findImports(path) { | |
return { | |
'contents': fs.readFileSync(path).toString() | |
} | |
} | |
var web3 = new Web3('http://localhost:9545') | |
var code = fs.readFileSync('./contracts/ZipToken.sol').toString(); | |
var inputs = { | |
'ZipToken.sol': fs.readFileSync('./contracts/ZipToken.sol').toString(), | |
}; | |
var compiledCode = solc.compile({ sources: inputs }, 1, findImports); | |
var abiDefinition = JSON.parse(compiledCode.contracts['ZipToken.sol:ZipToken'].interface); | |
var contract = new web3.eth.Contract(abiDefinition); | |
var byteCode = compiledCode.contracts['ZipToken.sol:ZipToken'].bytecode; | |
web3.eth.getAccounts().then((accounts) => { | |
contract.deploy({ data: byteCode }).send({ from: accounts[0], gas: 4700000 }).then(function () { | |
/** READING FILE LINE-BY-LINE */ | |
lr.on('error', function (err) { | |
console.log(err); | |
lr.close(); | |
}); | |
lr.on('line', function (lineno, line) { | |
if (lineno <= 100) { | |
console.log(lineno + " " + line); | |
} else { | |
lr.close(); | |
} | |
lr.pause(); | |
setTimeout(function () { | |
lr.resume(); | |
}, 100); | |
}); | |
lr.on('end', function () { | |
console.log("End"); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment