0

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";

web3.eth.sendTransaction({ 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 '22 at 09:55
  • @haxerl and how to fix it? – Mariia Synelnyk Jan 29 '22 at 10:30
  • @MariiaSynelnyk The problem is that Infura doesn't support sendTransaction you have to sign the transaction yourself (https://www.npmjs.com/package/@ethereumjs/tx) or use a middleware that will sign them for you (https://www.npmjs.com/package/@truffle/hdwallet-provider). Alternatively you could use ethers.js that have an integration with Infura. – Ismael Feb 07 '22 at 21:56

0 Answers0