/
SuperTitanFactory.js
51 lines (39 loc) · 1.5 KB
/
SuperTitanFactory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var Web3 = require('web3')
var solc = require('solc')
var fs = require('fs')
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var code = fs.readFileSync('SuperTitan.sol').toString()
var compiledCode = solc.compile(code)
var abiDefinition = JSON.parse(compiledCode.contracts[':SuperTitan'].interface)
var Contract = web3.eth.contract(abiDefinition)
var byteCode = compiledCode.contracts[':SuperTitan'].bytecode
//var _to = "0xff";
//var _value = 10;
//Input variables
var _initialSupply = 100;
var _name = 'name';
var symbol = 'N';
//This address must be constant , It cannot be changed , This value is set after getting the address of the contract .
//const address = 'addressofcontract' ;
deploy();
function deploy(){
var deployedContract = Contract.new({ data: byteCode, from: web3.eth.accounts[0], gas: 4700000 }, (err, res) => {
if (err) {
console.log(err);
return;
}
if (res.address) {
console.log(res.address);
contractFrom(res.address);
}
})
}
function contractFrom(address) {
// function newToken(uint256 _initialSupply, bytes32 _name, bytes32 symbol)
const DeployedContractRef = Contract.at(address);
var data = DeployedContractRef.newToken(_initialSupply, _name, symbol, { from: web3.eth.accounts[0], gas: 40000000 });
console.log(data);
DeployedContractRef.TokenAddedToTitan().watch(function(error, result) {
console.log(result.args.result);
})
}