I'm trying to send a lot of transactions to Ethereum with one program written in js. I use node js, web3 and infura ropsten. The problem is: if i send transactions at once, most of them just disappear. Trying to solve this problem, i send transactions with intervals. It works, but very slowly. I spend hour to send only 100 transactions. Is there any solution how to make it work faster and right? I was thinking about sending transaction after previous one starts pending, but I don't see how can I do that. Function sendRaw gets transaction number only after some time. This code reads the file, gets address, amount and optional data and uses method of smart contract to transfer tokens. Here is code:
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(err);
} else {
console.log(result);
Ntrans=result;
}
});
}
var nonce = web3.eth.getTransactionCount(address);
var gasPrice = web3.eth.gasPrice;
var gasLimit = 90000;
var fs = require("fs");
var buf1 = new Buffer(1024);
var buf2 = new Buffer(1024);
var buf3 = new Buffer(1024);
var i = 0;
var j = 0;
var k = 0;
var fd = fs.openSync('/home/kate/Desktop/file.txt', 'r+');
function recurs()
{
if(k==5) return -1;
j = 0;
do
{
fs.readSync(fd, buf1, j, 1, i);
i++;
j++;
}
while(buf1[j-1] != 32);
AddressC = String(buf1.slice(0, j-1))
console.log(AddressC);
j = 0;
do
{
fs.readSync(fd, buf2, j, 1, i)
i++;
j++;
}
while(buf2[j-1]!=32);
ValueT = Number(buf2.slice(0, j-1))
console.log(ValueT);
j = 0;
do
{
fs.readSync(fd, buf3, j, 1, i);
i++;
j++;
}
while(buf3[j-1]!=10);
TxC = String(buf3.slice(0, j-1));
txOptions =
{
nonce: web3.toHex(nonce),
gasLimit: web3.toHex(gasLimit),
gasPrice: web3.toHex(gasPrice),
to: contractAddress
}
console.log(TxC);
console.log(txOptions);
rawTx = txutils.functionTx(interface, 'foreignBuy', [AddressC,
ValueT, TxC], txOptions);
sendRaw(rawTx);
k++;
nonce++;
/* while(web3.eth.getTransactionReceipt(Ntrans)=="null")
{
} */
}
setTimeout(function(){
recurs();
}, 5000);
}
recurs();