I want to send a transaction with data using web3js, but I had an error like this

Returned error: The method eth_sendTransaction does not exist/is not available

const Web3 = require('web3')

const url_ropsten = 'https://ropsten.infura.io/v3/17425404118d470ab61c1cded765a510'
const web3 = new Web3(url_ropsten)

const message = "data";

    from: 'address1',
    to: 'address2',
    value: web3.utils.toHex(web3.utils.toWei('0.1', 'ether')),
    gasLimit: web3.utils.toHex(21000),
    data: web3.utils.toHex(message),
}, function (error, hash) {
    if (!error) {
        console.log('Transaction is - ', hash)
    else {
        console.log('Error is - ', error)
  • seem like you infura node is down so your web3 can't connect to get and use sendTransaction
    – haxerl
    Jan 29, 2022 at 9:55
  • @haxerl and how to fix it? Jan 29, 2022 at 10:30
  • @MariiaSynelnyk The problem is that Infura doesn't support sendTransaction you have to sign the transaction yourself (npmjs.com/package/@ethereumjs/tx) or use a middleware that will sign them for you (npmjs.com/package/@truffle/hdwallet-provider). Alternatively you could use ethers.js that have an integration with Infura.
    – Ismael
    Feb 7, 2022 at 21:56


Browse other questions tagged or ask your own question.