Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AbstractFruitFactory/e5975367bc77494940cc955f1061b962 to your computer and use it in GitHub Desktop.
Save AbstractFruitFactory/e5975367bc77494940cc955f1061b962 to your computer and use it in GitHub Desktop.
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