1

I'm developing a swap bot to swap tokens on BSC using PancakeSwap router. so this is my code

      import {account, web3} from '../index.js';

      const timeOut = Math.floor(new Date().getTime() / 1000 + 100);
      let swapMethod = routerContract.methods.swapExactETHForTokens(
        0,
        [db.wbnb, token],
        account.address,
        timeOut
      );
      let encodedData = swapMethod.encodeABI();
    
      const tx = {
        from: account.address,
        to: db.router,
        gas: 500000,
        gasPrice: '5000000000',
        data: encodedData,
        value: web3.utils.toWei(amount),
      };

      // Sign transaction
      const signedTX = await account.signTransaction(tx);

I have a problem with signTransaction method. As you can see, I sign transactions locally with account.signTransaction but it takes more than 500ms to sign a transaction. Is it normal to take this long? Is there a way to make it faster?

Also I use a public RPC node to send transaction. Is it faster to use services like Ankr?

2
  • Signing transactions locally should not take that long. Are you sure you have local signing configured correctly? Please edit and add more details about your configuration on this question. Jul 3 '21 at 10:01
  • Thanks for your response. I've added more info
    – M M
    Jul 3 '21 at 10:16
0

I found out there was a problem with my Web3 setup.

1
  • Hi. Could you give the details ? It might help someone else in the future. Jul 3 '21 at 13:51

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.