My following code previously works perfectly at Ganache, but when i switched it to Ropsten Network, it give captioned error. Here is Code:
async function finalSettersFunctions(){
var myFunc;
var myContAddr ;
for(i=0; i < contractAddressess.length; i++) {
myContAddr = contractAddressess[i]
for(j=1; j<finalSetters[i].length; j++) {
myFunc = finalSetters[i][j];
try {
await web3.eth.sendTransaction(
{from:account1,
to:myContAddr,
data: myFunc
}, function(err, receipt) {console.log("Normal Setters: ",receipt)});
} catch (error) {
console.log(" Normal Setters: ERROR !", error);
}
}
}
}
It should be noted that all my setters function are in encoded form, means all their methodId and parameters are embedded i.e. myFunc= 0x34fcd000000000033400000000000678888800000000........
Here is detailed error:
The method eth_sendTransaction does not exist/is not available
at Object.ErrorResponse (C:\Users\aa\node_modules\web3-core-helpers\src\errors.js:29:16)
at C:\Users\aa\node_modules\web3-core-requestmanager\src\index.js:140:36
at XMLHttpRequest.request.onreadystatechange (C:\Users\aa\node_modules\web3-providers-http\src\index.js:102:13)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (C:\Users\aa\node_modules\xhr2-cookies\dist\xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1143:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
Update: my provider is Web3.providers.HttpProvider("https://ropsten.infura.io/v3/
Update 2: i have changed my code as per comments (to sign my transaction and sendSignedTransaction) .... as is my new code
async function finalSettersFunctions(){
var myFunc;
var myContAddr ;
for(i=0; i < contractAddressess.length; i++) {
myContAddr = contractAddressess[i]
for(j=1; j<finalSetters[i].length; j++) {
myFunc = finalSetters[i][j];
/// here i have changed !
rawTx = {
nonce: await web3.eth.getTransactionCount(account1),
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: myContAddr,
data: myFunc
}
var tx = new Tx(rawTx);
tx.sign(privateKey2);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);
}
}
}
but it give this error Error: Returned error: invalid sender
account1
on infura? Of course, that's not possible (and you wouldn't want it to be either).