0

I made the following withdraw function in my smart contract:

function withdraw() public onlyOwner
{
    (bool success, ) = msg.sender.call{value: address(this).balance}("");    
}

I call this function in my mocha test as follows:

instance = await DataContract.deployed();
user1 = accounts[0];
await instance.withdraw({from:user1});

However, the call to the withdraw function gives the following error:

Error: Returned error: VM Exception while processing transaction: invalid opcode

Anyone has any idea what is wrong here ?

4
  • What happens if you remove onlyOwner? – Rob Hitchens Jun 7 at 17:43
  • I get the same error message if I remove OnlyOwner. – JohnyB Jun 8 at 11:54
  • Is the contract deployed? – Rob Hitchens Jun 8 at 17:55
  • Yes, on ganache. – JohnyB Jun 8 at 20:36

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.