0

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. Nov 23 '21 at 8:10
  • Yes, I switched to use ethers js and it worked
    – нεx
    Nov 24 '21 at 3:31
  • Thanks Hex, can we sign transactions using Privatekey offline using "ethers js"? If yes could you please share any reference link. Nov 24 '21 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.