forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendRawTransaction.js
61 lines (49 loc) · 1.3 KB
/
sendRawTransaction.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
var fs = require("fs");
var Web3 = require('web3');
var net = require('net');
var conf = require('./config');
var txm = require('./transactionManager');
var coder = require('./codeUtils');
//init web3
var web3 = new Web3();
var client = new net.Socket();
web3.setProvider(new web3.providers.IpcProvider(conf.ipc_path,client));
//sendRawTransaction
function sendRawTransaction()
{
web3.eth.getBlockNumber(function(e,d){
console.log(e+','+d);
var blocknumber=d+100;
var call_fun="add(uint256)";
var types=['uint256'];
var params=['15'];
var tx_data = coder.codeTxData(call_fun,types,params);
console.log('account:'+conf.account);
var postdata = {
data: tx_data,
from: conf.account,
to:conf.contract_addr,
gas: 1000000,
randomid:Math.ceil(Math.random()*100000000),
blockLimit:blocknumber
}
var signTX = txm.signTransaction(postdata,conf.privKey,null);
console.log("signTX : ",signTX);
web3.eth.sendRawTransaction(signTX, function(err, address) {
console.log(err,address);
if (!err)
{
console.log("发送交易成功!|",address);
process.exit();
return;
}
else
{
console.log("发送交易失败!",err);
process.exit();
return;
}
});
});
}
sendRawTransaction();