Can't seem to find the right function to ask the user to sign a transaction via metamask, this is my code so far:

  const bet = '102500000000000010'
  const account = '0xc8133b744147078a551b8d9c547414d427d8f579'

  web3.eth.getTransactionCount(account, function (err, nonce) {
    const data = Contract.methods.payBet(1553399554260556, bet).encodeABI();
    const tx = new Tx({
      gasPrice: 165335,
      gasLimit: 100000,
      to: "0x232b....",
      value: bet,

    //THIS tx.sign SHOULD BE THE METAMASK PART, since I dont have the user PK
    tx.sign(ethereumjs.Buffer.Buffer.from(privateKey, 'hex'));

    var raw = '0x' + tx.serialize().toString('hex');
    web3.eth.sendSignedTransaction(raw, function (err, transactionHash) {

What should I do to ask the user to sign the tx? I also tried to use web3.eth.sendTransaction but it is not supported by infura.

I'm abit lost here

1 Answer 1


Just use web3.eth.sendTransaction instead of web3.eth.sendSignedTransaction and Metamask will ask user to sign your transaction, and then will send signed transaction to Infura. See Metamask FAQ for more details.


Your Answer

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

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