0

I am facing a very strange error and I am still unable to figure out after spending more than 2 days. I am using truffle framework and latest version of Web3 library which is version 4.1.2.

  • I am using Truffle Develop Network: http://127.0.0.1:9545/
  • Wallet I am using: Metamask (with custom rpc network connecting to truffle)
  • Account Address: I have imported Truffle develop user account on the metamask.

Web3 library not working

  • New NPM Web3 Package : 4.1.2 or 4.1.1 or 4.1.0 ( I have installed latest versions using npm install web3 but none is working after 4.1.x )

Web 3 library which are working fine.

my contract code

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

contract Dummy {

string dummydata;

constructor()  
{
    dummydata = "test";
         
}
 function testdummyinsert(string calldata _dumy) public {

    dummydata = _dumy;
}

function getdummy() public view returns (string memory _ret) {
    return dummydata;
}

}

My html page statically loading these libraries on the page

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="node_modules/web3/dist/web3.min.js"></script>

My html page button trigger to send transaction to blockchain

//trigger
<input type="button" value="Add" onclick="onSubmitForm();">

This is a JS function onSubmitForm

async function onSubmitForm()
{

const _gasPrices = await web3.eth.getGasPrice();

const _gas = await mycontract.methods.testdummyinsert(fname).estimateGas({ from:userAddress});

const transaction = await mycontract.methods.testdummyinsert(fname).send({ from:userAddress, gasPrice: _gasPrices, gas: _gas });

}

I have tried promises, callbacks and tried all kinds code but for some reason Web3 version 4.X is not working at all for sending these simple transaction. The moment I degraded web3 npm package everything works fine. In 4.X version calling blockchain network works perfectly fine but only issue comes when you want to change the state by sending a transaction to the network.

Attached is the error picture enter image description here

Uncaught (in promise) Transaction has been reverted by the EVM: {"transactionHash":"0x50d17c29acf97e8fd0dfe84a8b37908b33a830463a895d6e76747cf1df190b83","transactionIndex":"0","blockNumber":"20","blockHash":"0xb8ff092abe1d312252803222d76fdf52dca6001e38be49f358b615941e2aa15e","from":"0x1a84bb86ebb0c6fc44a620c2869e776b3dd3c36a","to":"0x809f14942a3b5c6240fa94939c56c2018161624e","cumulativeGasUsed":"21069","gasUsed":"21069","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","status":"0","effectiveGasPrice":"2000000000","type":"2"} at http://localhost:3000/node_modules/web3/dist/web3.min.js:2:547663 at Generator.next () at http://localhost:3000/node_modules/web3/dist/web3.min.js:2:547312 at new Promise () at n (http://localhost:3000/node_modules/web3/dist/web3.min.js:2:547057) at t.getTransactionError (http://localhost:3000/node_modules/web3/dist/web3.min.js:2:547479) at http://localhost:3000/node_modules/web3/dist/web3.min.js:2:529773 at Generator.next () at s (http://localhost:3000/node_modules/web3/dist/web3.min.js:2:521726)

any ideas how to fix this problem using latest Web 4.x version?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.