-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.js
62 lines (47 loc) · 1.5 KB
/
example.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
51
52
53
54
55
56
57
58
59
60
61
62
Deployer = require("./utils/Deployer.js")
/* Set command line arguments */
const commandLineArgs = require('command-line-args')
const optionDefinitions = [
{ name: 'filename', alias: 'f', type: String},
{ name: 'arguments', alias: 'a', type: String},
{ name: 'gas', alias: 'g', type: String},
{ name: 'host', alias: 'h', type: String}
]
const options = commandLineArgs(optionDefinitions)
if (options['filename']) {
FILENAME = options['filename']
} else {
console.log("Please provide a filename")
process.exit()
}
if (options['host']) {
RPC_ADDRESS = options['host'];
} else {
RPC_ADDRESS = "http://localhost:8545"
}
if (options['arguments']) {
PARAMETERS = options['arguments'];
} else {
PARAMETERS = "Hello World"
}
if (options['gas']) {
GAS = options['gas'];
} else {
GAS = 500000
}
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider(RPC_ADDRESS));
Deployer.deployContract(FILENAME, RPC_ADDRESS, GAS, "Initial Greetings!", function(contractInstance) {
greeter = contractInstance;
greeting = greeter.greet.call();
console.log("[-->] Initial greeting:", web3.toAscii(greeting));
console.log("[+] Setting new greeting...");
greeter.setGreeting(PARAMETERS, {from: web3.eth.accounts[0], gas: GAS});
var myEvent = contract.Newgreeting({eventType: 1},{fromBlock: 0, toBlock: 'latest'});
myEvent.watch(function(error, result){
if ( !error) {
myEvent.stopWatching();
console.log("[-->] New Greeting:", web3.toAscii(result.args._newgreeting));
}
});
});