forked from eosdac/airdrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransactionpusher.js
41 lines (31 loc) · 1.1 KB
/
transactionpusher.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
//for [email protected]
const bn = require('bignumber.js')
var fs = require('fs');
const web3x = require('web3')
var Tx = require('ethereumjs-tx');
web3 = new web3x(new web3x.providers.HttpProvider("http://localhost:8545"));
var count = web3.eth.getTransactionCount("sender address");
var abiArray = JSON.parse(fs.readFileSync('eosDAC.json', 'utf-8'));
var contractAddress = "0x7e9e431a0B8c4D532C745B1043c7FA29a48D4fBa"; //eosDAC contract
var contract = web3.eth.contract(abiArray).at(contractAddress);
var nance = web3.toHex(count);
var rawTransaction = {
"from": "sender address",
"nonce": nance,
"gasPrice": "0x03B9ACA00",
"gasLimit": "0x15F90",
"to": contractAddress,
"value": "0x0",
"data": contract.transfer.getData("to address", amount, {from: "sender address"}),
"chainId": 0x01
};
var privKey = new Buffer('private key', 'hex');
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
if (!err)
console.log(hash);
else
console.log(err);
});