0

I am Developing EVoting system as my final year project and i am encountering this error RPC Error: execution reverted

Voting.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
contract Voting{
    
    address public owner = msg.sender;

    string myName = "Azid";

    function showData() public view returns (string memory)
    {
        return myName;
    }
   
}

Abi code of Voting.sol:

import web3 from './web3';

const address = '0x8aE711544c45157B72B5f32055EC992E9D0EB2F5';

const abi = 
[
    {
      inputs: [],
      name: 'owner',
      outputs: [{"internalType":"address","name":"","type":"address"}],
      stateMutability: 'view',
      type: 'function',
      constant: true,
      payable: undefined,
      signature: '0x8da5cb5b'
    },
    {
      inputs: [],
      name: 'showData',
      outputs: [{"internalType":"string","name":"","type":"string"}],
      stateMutability: 'view',
      type: 'function',
      constant: true,
      payable: undefined,
      signature: '0xbca02ea8'
    }
]

export default new web3.eth.Contract(abi, address);

When I call owner it works fine but when I call showData it show me the error.

Register.js:

import voting from '../../voting';

//Creating Register Functional Component
const Register = props =>{
    const check = async () =>{
        console.log("checking");
        const ok = await voting.methods.showData().call();
    }

    //Returning JSX
    return(
        <Aux>
    
            <button onClick={check}>Check</button>
            
        </Aux>
    )
}

//Exporting Register Functional Component
export default Register;
1
  • You should post your answer about fixing const address = '0x8aE711544c45157B72B5f32055EC992E9D0EB2F5';
    – eth
    Sep 12 at 4:00
0

The smart contract seems right, you're not showing how you call owner but the await seems fine assuming voting has the proper web3 credentials in the voting file. Try adding a from address and a gas as parameters of the call, for a call the gas will be returned anyways so it should help with troubleshooting

1
  • I was using old deployed address after it's working fine thanks
    – Mahad Ali
    Sep 10 at 18:57
0

I forgot to changed my deployed address and after I changed that address it worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.