0
const Web3=require('web3');
var Tx = require('ethereumjs-tx').Transaction;               
const web3=new Web3('https://ropsten.infura.io/v3/1e9dedc0e54e44559345e5636c004114');

var account1='0x48ccbB6426E76113789cd232e479e3f1E5ad0d5f';
var private_key_1=Buffer.from(process.env.PRIVATE_KEY_1,'hex');
                
var contractAddress='0x5A5Efb98d10616F155ef0b8342F264E130D1d2f3';

 var contractAbi=[{"inputs":[],"name":"Message","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMessage","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"newMessage","type":"string"}],"name":"setMessage","outputs":[],"stateMutability":"nonpayable","type":"function"}];
               
const contract=new web3.eth.Contract(contractAbi,contractAddress)
    
 web3.eth.getTransactionCount(account1,(err,txCount)=>{                        
               const txObject={
                   nonce:web3.utils.toHex(txCount),
                   gasLimit:web3.utils.toHex(600000),
                   gasPrice:web3.utils.toHex(web3.utils.toWei('100','gwei')),
                   to:contractAddress,
                   data:contract.methods.setMessage("king khan").encodeABI(),
               }
               const tx=new Tx(txObject,{chain:'ropsten'});
               tx.sign(private_key_1) 
              
               const serializedTx=tx.serialize()
               
               const raw = '0x' + serializedTx.toString('hex')
                 web3.eth.sendSignedTransaction(raw,(err,txHash)=>{
                   console.log('txHash:',txHash)
                   console.log('err:',err)
               })
               })
  

Error

 error:        var error = new Error(message);
                    ^

Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x2b507c9a8ea2b582d2d405244296f725cba1c00204f5119bf4812201f995a23d",
  "blockNumber": 11424966,
  "contractAddress": null,
  "cumulativeGasUsed": 21728,
  "effectiveGasPrice": "0x174876e800",
  "from": "0x48ccbb6426e76113789cd232e479e3f1e5ad0d5f",
  "gasUsed": 21728,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "status": false,
  "to": "0x5a5efb98d10616f155ef0b8342f264e130d1d2f3",
  "transactionHash": "0x3fa8bc349da70408e9bf8e559833812023bdba790a0ccec79fb37eb3b3e72bce",
  "transactionIndex": 0,
  "type": "0x0"
}
    at Object.TransactionError (E:\python\project\block chain\learning steps\web3\node_modules\web3-core-helpers\lib\errors.js:87:21)
    at Object.TransactionRevertedWithoutReasonError (E:\python\project\block chain\learning steps\web3\node_modules\web3-core-helpers\lib\errors.js:98:21)
    at E:\python\project\block chain\learning steps\web3\node_modules\web3-core-method\lib\index.js:393:57
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  receipt: {
    blockHash: '0x2b507c9a8ea2b582d2d405244296f725cba1c00204f5119bf4812201f995a23d',
    blockNumber: 11424966,
    contractAddress: null,
    cumulativeGasUsed: 21728,
    effectiveGasPrice: '0x174876e800',
    from: '0x48ccbb6426e76113789cd232e479e3f1e5ad0d5f',
    gasUsed: 21728,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    to: '0x5a5efb98d10616f155ef0b8342f264e130d1d2f3',
    transactionHash: '0x3fa8bc349da70408e9bf8e559833812023bdba790a0ccec79fb37eb3b3e72bce',
    transactionIndex: 0,
    type: '0x0'
  }
}
1
  • It would be nice to format the text according to the rules of Stackoverflow and attach the text of the smart contract
    – Mad Jackal
    Nov 14 '21 at 20:32

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.