Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
Can Someone explain ENUM, EMIT, EVENT in solidity for me
 enum Status{ Vacant, Occupied }
    Status currentStatus;

 event Occupy(address _occupant, uint _value);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As in some other programming languages, enum (docs) allows you to aggregate multiple values to one datatype, where only one of the values is active.

In your case, the currentStatus can be Vacant (integer value 0), or it can be Occupied (integer value 1). But never can be "none of these", nor "both", nor "anything else".

pragma solidity ^0.8;

contract MyContract {
    enum Status {
        Vacant,
        Occupied
    }

    Status currentStatus;

    // you can effectively pass `0` or `1` integer value here
    function setCurrentStatus(Status _currentStatus) external {
        currentStatus = _currentStatus;
    }

    function getCurrentStatusVerbose() external view returns (string memory) {
        if (currentStatus == Status.Vacant) {
            return "The current status is Vacant";
        } else if (currentStatus == Status.Occupied) {
            return "The current status is Occupied";
        }
    }
}

Events (docs) are readable by off-chain apps, not not readable by other contracts. Usually, the off-chain app listens to these events being emitted to perform an action on its end.

pragma solidity ^0.8;

contract MyContract {
    event Occupy(address _occupant, uint _value);

    enum Status {
        Vacant,
        Occupied
    }

    Status currentStatus;

    function setCurrentStatus(Status _currentStatus) external {
        currentStatus = _currentStatus;
        // emitting the `Occupy` event
        emit Occupy(msg.sender, uint(_currentStatus));
    }
}

Off-chain app:

myContract.on('Occupy', async (event) => {
    updateOccupancyInExternalDB(event);
});

A real-life example is the Transfer() event defined the ERC-20 token standard. When a token contract emits this event, it means that a token transfer occured. Blockchain explorers (such as Etherscan) listen to these events and update the token balance info in their own databases (subtract from the sender balance and increase the receiver balance in their own DB).

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda