1

I'm working with metamask and was testing a transaction that should trigger a revert statement inside my contract. When the error is thrown metamask gives the following output: image this was while using Firefox with Metamask extension installed

the following is the result of using on Chrome without the metamask extension image

So as you can see i suppose the error message the extension gets its the same as the one on screenshot #2

and here is the code that produces the throw image

my question is, do we have a way of catching these errors in a more 'elegant fashion' so we can know what caused the error or this the only way of catching such errors.

The approach i'm using here is similar to How to catch JSON RPC exception in front end web3 EDIT: here is my contract's code:

pragma solidity ^0.4.18;

contract Ive {

    address public creator;
    address public owner;


    mapping (address=>bool) allowedVisitors;
    address[] allowedVisitorsList;

    struct Client {
        address wallet;
        string apellido1;
        string apellido2;
        string apellidoCasada;
        string nombre1;
        string nombre2;
        string fechaNacimiento;
        address modifiedBy;
    }

    Client[] private clients;

    event OwnerAssigned(
        address creator,
        address owner
    );

    event VisitorAllowed(
        address owner,
        address newVisitor
    );

    event VisitorDisallowed(
        address owner,
        address newVisitor
    );

    modifier onlyAllowed() {
        if(allowedVisitors[msg.sender] == false)
            revert("Account is not allowed to obtain client info");
        _;
    }

    modifier onlyCreator() {
        if(msg.sender != creator)
            revert("Only creator can execute this action");
        _;
    }

    modifier onlyOwner() {
        if(msg.sender != owner)
            revert("Only owner can execute this function");
        _;
    }

    constructor () public {
        creator = msg.sender;
        owner = msg.sender;
    }

    function setClientInfo (
        string apellido1,
        string apellido2,
        string apellidoCasada,
        string nombre1,
        string nombre2,
        string fechaNacimiento
    ) 
        external returns (uint) 
    {
        Client memory newClient;

        newClient.apellido1 = apellido1;
        newClient.apellido2 = apellido2;
        newClient.apellidoCasada = apellidoCasada;
        newClient.nombre1 = nombre1;
        newClient.nombre2 = nombre2;
        newClient.fechaNacimiento = fechaNacimiento;
        newClient.modifiedBy = msg.sender;

        clients.push(newClient);

        return clients.length;
    }

    function getClientsLength () view public returns (uint) {
        return clients.length;
    }

    function setOwner(address _owner) onlyOwner external {
        owner = _owner;
        allowVisitor(_owner);
        // emit OwnerAssigned(msg.sender, _owner);
    }

    function obtainOwner() view external returns (address){
        return owner;
    }

    function allowVisitor(address visitor) public {
        if(!allowedVisitors[visitor]) {
            allowedVisitors[visitor] = true;
            allowedVisitorsList.push(visitor);
            emit VisitorAllowed(msg.sender, visitor);
        }
    }

    function isAllowedAccount(address account) view public returns (bool) {
        return allowedVisitors[account];
    }

    function disallowVisitor(address account) onlyOwner external {
        allowedVisitors[account] = false;
        emit VisitorDisallowed(msg.sender, account);
    }

    function getVisitorsLength() view public returns (uint) {
        return allowedVisitorsList.length;
    }

    function obtainClient(uint32 index) view onlyAllowed public returns (string, string, string, string) {
        return (clients[index].nombre1, clients[index].apellido1, clients[index].fechaNacimiento, clients[index].apellido2);
    }

    function getAllowedVisitors() view onlyOwner public returns (address[]) {
        return allowedVisitorsList;
    }

}
  • not easy to tell without the contract code – mirg Jun 13 '18 at 2:31
  • added the contract code – Roberto C. Jun 13 '18 at 4:26
  • oh sorry I misunderstood your question was actually not necessary the contact code. So far I guess that's the best way until they implement a better way as per this github.com/ethereum/EIPs/issues/136 – mirg Jun 13 '18 at 4:35

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.