Why is my web3 "signTransaction" function hanging?

Viewed 371

I'm trying to send a transaction to a custom chain/RPC using the web3 javascript library. When I try to use the web3.eth.signTransaction function, my program hangs and doesn't continue. Here is my code. The last log that shows up in the terminal (I'm using Nodejs) is "signing transaction...", so I assume the signTransaction function is the problem.

import Web3 from 'web3'
import WalletConnectProvider from '@walletconnect/web3-provider'
...
      console.log('connecting to private chain...')
      const provider = new WalletConnectProvider({
        rpc: {
          74: 'private chain RPC is here...',
        },
        chainId: 74,
      })
      console.log('connecting to web3...')
      const web3 = new Web3(provider)
      const txParams = {
        to: 'wallet address is here',
        value: 0,
        gasPrice: '10',
        gas: '21010',
        data: Web3.utils.toHex(publicKey),
        chainId: 74,
        from: 'wallet address is here',
      }
      console.log('signing transaction...')
      console.table(web3.eth.signTransaction)
      const {raw} = await web3.eth.signTransaction(
        txParams, 'my private key is here'
      )
      console.log(raw)
      console.log('sending transaction...')
      const sentTransaction = await web3.eth.sendSignedTransaction(raw)

I've used MetaMask to connect using the same RPC address and chain ID and it worked as intended, and I was able to send transactions.

0 Answers
Related