2

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

3
  • 2
    On ganache the accounts are unlocked by default, you should sign the transaction and use send signed transaction instead
    – Majd TL
    Dec 25, 2019 at 8:42
  • 1
    Have you unlocked account1 on infura? Of course, that's not possible (and you wouldn't want it to be either). Dec 25, 2019 at 8:47
  • 1
    @MajdTL thanks for your response... could explain it with solution by given it in your answer...
    – Amir Ali
    Dec 25, 2019 at 8:50

2 Answers 2

2

Have you unlocked account1 on Infura?

Of course, that's not possible (and you wouldn't want it to be either).

This mode of operation is available only when you're using your own private node, so that others will not be able to exploit your account.

And even then, it is not a recommend mode of operation, since anyone hacking your node will be able to exploit your account at will.

So it is designated primarily for testing purpose (as is the case with Ganache, see the comment to your question).

Otherwise, it is recommended to sign the transaction with your private key and then send it to the node (and again - with Infura nodes being public, it is not just the recommended mode of operation, but the only one available).

6
  • 1
    i am signing .. but its give Error: Returned error: invalid sender... 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);
    – Amir Ali
    Dec 25, 2019 at 9:25
  • 1
    @AmirAli: That's a different error which deserves a different question, if I am to judge by the amount of information that you posted in the comment above. Dec 25, 2019 at 9:32
  • 1
    i have updated such error in my update 2.. if still it deserve a different question, i can post it .. no problem for me ..
    – Amir Ali
    Dec 25, 2019 at 9:33
  • @AmirAli: "but it give this error Error: Returned error: invalid sender" - which lines gives this error??? Dec 25, 2019 at 9:42
  • btw. the another error has been solved by var tx = new Tx(rawTx, {chain:'ropsten', hardfork: 'petersburg'}); thanks for your time
    – Amir Ali
    Dec 25, 2019 at 9:43
0

async function finalSettersFunctions(){ var myFunc; var myContAddr ; for(i=0; i < contractAddressess.length; i++) { myContAddr = contractAddressess[i] for(j=1; 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); 
        }
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.