1

Guys I am trying to sign and send a transaction to Rinkeby test network using Infura and web3.

However, i have been stuck in the following error Error: Returned error: transaction could not be decoded: unsigned transactions not supported

and you can see my code below:

import style from './main.css'
import web3 from 'web3'
import {Transaction} from '@ethereumjs/tx'


var gateway = new web3('https://rinkeby.infura.io/v3/MY-INFURA-PROJECT-ID')
var abi = [
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [],
      "name": "starName",
      "outputs": [
        {
          "internalType": "string",
          "name": "",
          "type": "string"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [],
      "name": "starOwner",
      "outputs": [
        {
          "internalType": "address",
          "name": "",
          "type": "address"
        }
      ],
      "stateMutability": "view",
      "type": "function",
      "constant": true
    },
    {
      "inputs": [],
      "name": "claimStar",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    }
  ]

var con = new gateway.eth.Contract(abi,'0x444C514e0AE9dA12Db399A2d30124ADbB96f8EC4')

const privateKey = new Buffer.from('MY-PRIVATE-KEY','hex')

const txParams = {
  from: '0x20f2E66DA9315D447b22059F154ed1E016d41369',
  nonce: '0x00',
  gasPrice: '0x09184e72a000',
  gasLimit: '0x2710',
  to: '0x9b1B39881355869821f83096eB1a2B9B4DF15286',
  value: '0x00',
  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
}


const tx = new Transaction(txParams, {chain: 'rinkeby'})


gateway.eth.sendSignedTransaction('0x' + tx.serialize().toString('hex'))

I tried to to use etheruemjs-tx and the same problem exists.

is there a solution or there easier solution using different library?

3
  • Hex, did you figured out this issue, I am also facing same issue when try to broadcast a "EIP1559" signed transaction using "@ethereumjs/tx" npm library. Commented Nov 23, 2021 at 8:10
  • Yes, I switched to use ethers js and it worked
    – нεx
    Commented Nov 24, 2021 at 3:31
  • Thanks Hex, can we sign transactions using Privatekey offline using "ethers js"? If yes could you please share any reference link. Commented Nov 24, 2021 at 7:36

1 Answer 1

0

Okay I've finally found the answer everybody is looking for!

What's breaking with the previous implementation of ethereumjs-tx is that the signed data is no longer added to the transaction instance. It means it's just present during the .sign line, it is not reachable after.

A fix regarding your implementation, that I've tested, would consist of just compacting the sign and the serialization on one line: const serializedTx = transaction.sign(privateKey).serialize().toString('hex')

Then you can call sendSignedTx('0x' + serializedTx)

Works perfectly with @ethereumjs/tx^3.5.2

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.