Error encountered: The EVM has reverted the transaction

After successfully deploying this basic smart contract using Remix, I encountered an issue when trying to interact with it through web3.js in my upcoming app. I used the evm version: paris for deployment and everything worked smoothly on Remix IDE.

Here is the code snippet of the smart contract:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Counter {
    uint256 private count = 0;

    function setCount(uint256 val) external payable  {
        count = val;
    }

    function viewCount() external view returns (uint256) {
        return count;
    }
}

In my web3.js interaction attempt, I expected a successful transaction but instead received an error in the transactionReceipt:

error: TransactionRevertedWithoutReasonError: Transaction has been reverted by the EVM:
 {"blockHash":"0x6138b0cdd3a047486419f066ef056aab7b28c11bbaea82b5812c095f96cf86c7","blockNumber":"1382940","cumulativeGasUsed":"21046","from":"0x9ded1ae475bd50a15dde12bbc34b7ea04969cd0b","gasUsed":"21046","logs":[],"logsBloom":"0x00000000000000000000000000000000000..."

Currently investigating the reason behind this unexpected error.

Answer №1

After hours of searching, a breakthrough has been made. I have successfully executed the code and everything is running smoothly with the following approach -

const contract = new web.eth.Contract(ABI, address);
const gasEstimate = await contract.methods
      .setCount("10")
      .estimateGas({ from: accounts[0] });
console.log(gasEstimate);

const encode = await contract.methods.setCount(10).encodeABI();

const tx = await web.eth.sendTransaction({
        from: accounts[0],
        to: address,
        gas: gasEstimate,
        data: encode,
});

Achieved the desired output by using this method for transaction execution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues with link behavior when using Angular UI-Router

I am just starting to learn AngularJS and I'm trying to figure out how to pass a parameter using anchor tags within the $stateProvider code. I've been attempting to do so, but it doesn't seem to be working. Can someone guide me on the correc ...

Issues arise with AJAX post

I have run into an issue with my jQuery and Codeigniter setup while trying to update the database via AJAX. Despite having the following code in place, nothing seems to be happening or getting sent to my controller when the button is clicked... Snippet of ...

Remove Cookies and Log out on the server side using Next.js

I have a requirement to verify the validity and expiration of a token in the getInitialProps function. If the token is expired, I need to clear the Cookies from the browser and sign out the user. Here's my current approach ... const checkTokenExpirat ...

When using the <Routes> component, it will not render a component that acts as a container for multiple <Route> elements

Upon wrapping my component in <Routes>, I encountered this warning: Warning: [Categories] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment> In App.js: const App = () => ...

Managing the state of dynamically generated tabs within a NextJS application

Looking to develop a web app in Next.js that includes tabs components. The goal is to manage various entities within each tab, such as utilizing a search bar to select different products. Upon selecting a product, a new tab will be generated with the produ ...

Tips for storing mustache templates for rendering in Node.js

My data is stored in the following format: let data = {"list" :[ { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98f9fafb8afef0f9f5e8f4fdb6fbf7f5">[email protected] ...

Unable to display video content within react quill editor

I am experiencing an issue with playing videos in React Quill when I set to resize images. Every time I add a video, it gets resized like a photo and cannot be played. Does anyone have a solution for this? Here is my code: Type your code here import React ...

Transferring a PDF document to Next.js

I am facing an issue while trying to upload a PDF file (CV) on next js. Everything seems fine according to my expectations, but when I console.log(req.data) it displays [object:object] Please note: When I console.log the data in frontend, it works fi ...

Access the properties of a JSON object without specifying a key

I am dealing with a collection of JSON arrays structured like this: [ { team: 111, enemyId: 123123, enemyTeam: '', winnerId: 7969, won: 1, result: '', dat ...

Does the onchange function in the dropdown list only work when the first item is changed?

Here is a snippet of my HTML code featuring a list item generated from a database using a foreach loop: <select class="form-control select" id="inventoryitem" name="inventoryitem" onchange="getunit();"> <option>---Select an item---</o ...

Accessing stored web pages / Browser as an interactive interface

I have a couple of questions I need help with. The first one is about how to open a saved HTML file in a browser without an internet connection. Next, I'm looking for advice on using the browser as a user interface for a desktop image viewing program ...

Using Next.js in combination with Axios results in a pending promise

I am attempting to retrieve data from a free API https://catfact.ninja/fact using axios in nextjs, but I keep seeing a promise pending status. httpClient.js: import axios from "axios"; const GET_CATS = "https://catfact.ninja/fact"; e ...

What is the best approach to including files in addition to other data fields when calling a webmethod in asp.net using a jquery ajax request?

My webform contains a variable number of textboxes and dropdowns. To send data to the server-side webmethod, I am utilizing the following code: $.ajax({ type: "POST", url: "SupplierMaster.aspx/RegisterSupplier", data: JSON.stringify({ ...

The `background-size` property in jQuery is not functioning as expected

I am facing the following issue: When I click on a div with absolute positioning, I want to animate its position, width, and height. In addition, I want to change the background-size using jQuery. However, the problem is that all CSS properties are updat ...

Creating a directive in AngularJS to automatically populate select options with custom values

As someone who is relatively new to creating directives, I am looking to develop a directive that will assist me in my application. What I aim to achieve is a select element directive that comes pre-populated with options and is self-contained. All I need ...

Only one condition is met when using the Javascript if statement with the :checked and .bind methods

I need help creating an Override Button to disable auto-complete for a form using Javascript. I want the div "manualOverrideWarning" to display a warning if the button is selected, but my current function only works the first time the user presses the butt ...

Is there a way to modify the appearance of blocks in Scratch/Blockly?

I am currently working on customizing the appearance of the blocks in Scratch by looking into adjusting the GitHub repository of scratch-blocks (https://github.com/LLK/scratch-blocks). There is a chance that I might need to modify the GitHub repository of ...

Retrieve the Typescript data type as a variable

I have the following components: type TestComponentProps = { title: string; } const TestComponent: React.FC<TestComponentProps> = ({ title, }) => { return <div>TestComponent: {title}</div>; }; type TestComponent2Props = { bod ...

Can a function be activated in JavaScript when location permission is declined?

Background: Following up on a previous question regarding the use of getCurrentPosition and async functions. I am currently working on The Odin Project and attempting to create a basic weather application. My goal is to include a feature that automatically ...

Facebook and the act of liking go hand in hand, growing together

I am working on a website where I want to include Facebook like and share buttons with counters. To achieve this, I used Facebook's own links to generate these buttons for the specific URL. The issue I encountered is that when I like or share the page ...