0

Getting this error only on some of the wallets I tried. Too low is for sure not the problem. Working on infura.

sendEth = async function(fromm, frommPUB){
      fromAcc = web3.eth.accounts.privateKeyToAccount(fromm);
      allTokWals2 = $('#adtokens')[0].getElementsByClassName('adtokens-itm');
      var toAddLen = document.getElementsByClassName('sendtokens-itm').length;
      var nonceCo = await web3.eth.getTransactionCount(frommPUB);

      var gasToUse = 21000;

      for (var i = 0; i < allTokWals2.length; i++) {
        gCost = allTokWals2[i].getAttribute('gascost');
        if (toAddLen > 1) {
          gCost = gCost*toAddLen;
        }
        gCost = gCost*tokenDefGwei* 1e9;//10 gwei
        var pubKey= allTokWals2[i].getElementsByClassName('adtokens-public')[0].value;//send to

        if (retok.test(pubKey)) {
          await web3.eth.getBalance(frommPUB, (err, resp) => {
            if(err!=null){
              console.log(err)
            }else{
              console.log('eth balance:    '+web3.utils.fromWei(resp.toString(), 'ether'));
            }
          });

          console.log('eth to send  '+gCost);
          console.log('Tx fee  '+(21000*tokenDefGwei * 1e9));
          console.log('Actual cost in eth  '+web3.utils.fromWei(((gasToUse*tokenDefGwei * 1e9)+gCost).toString(), 'ether'));
          console.log('nonce Count  '+nonceCo);
          await web3.eth.accounts.privateKeyToAccount(fromm);
          web3.eth.accounts.signTransaction({to:pubKey, chainId: 1, value:gCost, gas: gasToUse, gasPrice: tokenDefGwei * 1e9, nonce: nonceCo+i}, fromm, function(err, r) {
            console.log(r);
            if (err != null) {
              console.log(err);
            }else {
              web3.eth.sendSignedTransaction(r.rawTransaction, function(errs, receipt) {
                if (errs != null) {
                  console.log(errs);
                }else {
                  web3.eth.getBalance($('#ethAdd').val(), function(err, balance) {
                    $('#ethRem').text('eth balance: '+window.ethDecim(balance));
                  });
                }
                console.log(receipt);
              });
            }
          });
        }
      }
    }
0

Found the bug. Private key needs to start with '0x' :|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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