I am trying to send some test ether on Ropsten network using Infura but I can not make a transaction. Code works locally with testrpc but not with Infura
var Web3 = require('web3');
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');
var lightwallet = require('eth-lightwallet');
var txutils = lightwallet.txutils;
var web3 = new Web3(
new Web3.providers.HttpProvider('https://ropsten.infura.io/<token>')
//new Web3.providers.HttpProvider('http://localhost:8545')
);
var address = '0xadaD904F70ec8323fEd1734614d78D2145222322';
var address2 = '0x5858599f16c46fa33238313A412eE9f0491EBef3';
var key = '<KEY>';
var key2 = '<KEY>';
var amount = web3.toWei(1, "ether");
var balance = web3.eth.getBalance(address);
var value = web3.fromWei(balance, 'ether');
console.log(value);
function sendRaw(rawTx) {
var privateKey = new Buffer(key, 'hex');
var transaction = new tx(rawTx);
transaction.sign(privateKey);
var serializedTx = transaction.serialize().toString('hex');
web3.eth.sendRawTransaction(
'0x' + serializedTx, function(err, result) {
if(err) {
console.log('error');
console.log(err);
} else {
console.log('success');
console.log(result);
}
});
}
var rawTx = {
nonce: web3.toHex(web3.eth.getTransactionCount(address)),
gasLimit: web3.toHex(21000),
to: address2,
from:address,
value: web3.toHex(web3.toBigNumber(amount))
}
sendRaw(rawTx);
As you can notice I am logging ether on address but no matter how many times I send the transaction it stays eq to 1eth.
Any ideas what I am doing wrong?