-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendTx.js
57 lines (50 loc) · 1.41 KB
/
sendTx.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
const Web3 = require("web3");
const OPTIONS = {
defaultBlock: "latest",
transactionConfirmationBlocks: 1,
transactionBlockTimeout: 5
};
const web3 = new Web3(
new Web3.providers.WebsocketProvider("ws://localhost:8545"),
// Web3.providers.HtttpProvider("http://localhost:8545")
null,
OPTIONS
);
console.log(
web3.currentProvider.constructor.name,
"version:",
web3.version,
"web3.eth.transactionConfirmationBlocks:",
web3.eth.transactionConfirmationBlocks,
"web3.transactionConfirmationBlocks:",
web3.transactionConfirmationBlocks
);
sendTx()
.then(receipt => {
console.log("Got receipt");
})
.catch(error => console.log("Got error:", error));
async function sendTx() {
const accounts = await web3.eth.personal.getAccounts();
const tx = web3.eth
.sendTransaction({
to: accounts[1],
from: accounts[0],
value: web3.utils.toWei("0.1", "ether")
})
.on("transactionHash", txHash => {
//web3.currentProvider.send("evm_mine"); // execution of it seems to be blocked by sendTransaction in beta52
console.log("on transactionHash", txHash);
})
.on("receipt", receipt => {
console.log("on receipt");
})
.on("confirmation", (confirmationNumber, receipt) => {
console.log("on confirmation", confirmationNumber);
})
.on("error", error => {
console.log("on error", error);
});
const receipt = await tx;
return receipt;
}