Solidity – Troubleshooting RPC Error: Execution Reverted

blockchainsolidity

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;

Best Answer

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