title: Web3 sending EIP-1559 Transaction Completed Successfully but got back an Error: invalid remainder
body: <p><strong>Overview</strong></p>
  <p>I am able to send an EIP-1559 transaction through Rinkeby Testnet with Web3, the transaction completes without any trouble and I do get my Ether in my Metamask Rinkeby Account.
  The thing is that I am getting an <em>Error: invalid remainder</em> after the transaction completes and my program stops immediately.</p>
  <p><strong>Code</strong></p>
  <pre><code>// EIP-1559 Transanction
  // Loading dependencies
  const fs = require( 'fs' ).promises;
  const Web3 = require( 'web3' );
  const HDWalletProvider = require( '@truffle/hdwallet-provider' );
  const { mnemonicGenerate } = require( '@polkadot/util-crypto' );
  const { FeeMarketEIP1559Transaction } = require( '@ethereumjs/tx' );
  const Common = require( '@ethereumjs/common' ).default;
  
  async function main () {  
      // Infura rinkeby's url
      const infuraRinkeby = &quot;https://rinkeby.infura.io/v3/4fa53ccf01504cc69f0dcbdfdaa38acf&quot;;
  
      // Generating bip39 mnemonic
      // const mnemonic = mnemonicGenerate();
  
      // Loading previously generated mnemonic
      const mnemonic = ( JSON.parse( await fs.readFile( &quot;./private/mnemonic.json&quot; , &quot;utf8&quot; ) ) ).mnemonic;
  
      // Creating wallet from mnemonic and saving it as a web3 provider with infura
      const provider = new HDWalletProvider( mnemonic , infuraRinkeby );
  
      // Passing the web3 provider to web3
      const web3 = new Web3( provider );
  
      // Getting sending address and balance
      const sendingAddress = ( await web3.eth.getAccounts() )[0];
      var sendingAddressBalance = await web3.eth.getBalance( sendingAddress );
  
      console.log( &quot; &quot; );
      console.log( Array( 75 ).join( &quot;=&quot; ) );
      console.log( &quot;Before Transaction&quot; );
      console.log( &quot;Address: &quot; + sendingAddress );
      console.log( &quot;Balance: &quot; + sendingAddressBalance );
  
      // Setting receiving address
      const receivingAddress = &quot;0x24620ddf8474c89C0Fc0c916acBcF4029C4eB47F&quot;;
  
      // Getting the private key for the sending address account
      const preKey = ( provider.wallets )[ sendingAddress.toLowerCase() ].privateKey.toString( 'hex' );
      const privateKey = Buffer.from( preKey , 'hex' );
  
      // Setting chain
      var chain = new Common( { chain : 'rinkeby', hardfork : 'london' } );
  
      // Constructing the raw transaction
      // To 'Speed Up' a transaction like Metamask just send a new transaction with the same nonce but with higher gas
      const rawTx = {
          &quot;from&quot;                  :   web3.utils.toHex( sendingAddress ),
          &quot;to&quot;                    :   web3.utils.toHex( receivingAddress ),
          &quot;gasLimit&quot;              :   web3.utils.toHex( 210000 ),
          &quot;maxFeePerGas&quot;          :   web3.utils.toHex( web3.utils.toWei( '1.5' , 'gwei' ) ),
          &quot;maxPriorityFeePerGas&quot;  :   web3.utils.toHex( web3.utils.toWei( '1.5' , 'gwei' ) ),
          &quot;value&quot;                 :   web3.utils.toHex( web3.utils.toWei( '0.1' , 'ether' ) ),
          &quot;data&quot;                  :   web3.utils.toHex( 'This is my example' ),
          &quot;nonce&quot;                 :   web3.utils.toHex( await web3.eth.getTransactionCount( sendingAddress , 'pending' ) ),
          &quot;chainId&quot;               :   &quot;0x04&quot;,
          &quot;accessList&quot;            :   [],
          &quot;type&quot;                  :   &quot;0x02&quot;
      };
  
      // Creating a new transaction
      const tx = FeeMarketEIP1559Transaction.fromTxData( rawTx , { chain } );
  
      // Signing the transaction
      const signedTransaction = tx.sign( privateKey );
      
      // Generating transaction Hash
      const txHash = await web3.utils.sha3( '0x' + signedTransaction.serialize().toString( 'hex' ) );
      console.log( &quot;Tx Hash: &quot; + txHash );
  
      // Sending transaction
      await web3.eth.sendSignedTransaction( '0x' + signedTransaction.serialize().toString( 'hex' ) )
      .on( 'error' , function( error ) {
          console.error( error )
      } );
  
      console.log( 'After Transaction' );
      sendingAddressBalance = await web3.eth.getBalance( sendingAddress );
      console.log( &quot;Address: &quot; + sendingAddress );
      console.log( &quot;Balance: &quot; + sendingAddressBalance );
      console.log( Array( 75 ).join( &quot;=&quot; ) );
      console.log( &quot; &quot; );
  };
  
  main();
  </code></pre>
  <p><strong>Screenshot of Error</strong></p>
  <p><a href="https://i.stack.imgur.com/EzBTb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EzBTb.png" alt="enter image description here" /></a></p>
  <p><strong>Questions</strong></p>
  <ul>
  <li><p>How do I fix this error?</p>
  </li>
  <li><p>I am trying to add this example in a project repository as a portfolio to showcase in a future personal website but I can't because it crashes after sending the transaction (the transaction is successful). <strong>How can I catch the error without crashing the whole program?</strong> (Already tried try catch and didn't solve anything).</p>
  </li>
  <li><p>If there a library that is causing the error, <strong>what other library can I use to replace the one crashing the program?</strong></p>
  </li>
  </ul>
  <p><strong>Transaction Link Proof of Transaction Completion</strong></p>
  <p><a href="https://rinkeby.etherscan.io/tx/0xb9395662b14773b2dc620e8861b9dc040e79f57883f502219feb2f14caa0347c" rel="nofollow noreferrer">Rinkeby Transaction from rinkeby.etherscan.io</a></p>
  <p>If you go to data in the transaction link and convert from Hex to String you will see the message <em>This is my example</em>.</p>