Here is an example article:
Ethereum Compilation Error: “Compile Failed” in Solidity
When developing a new smart contract for the Ethereum blockchain, it is not uncommon to encounter compilation errors. In this article, we will explore an error that occurs when compiling solid code using Hardhat.
Problem
In your Hardhat project, you have defined a contract called Marketplace
with multiple events. However, during compilation, you encounter an error that prevents the contract from successfully compiling. Specifically, the error message indicates that `Compile failed.''
Error Message

The error message is quite detailed and provides valuable information about what is wrong. The exact text of the error message will depend on your version of Solidity, but here is an example of the result:
Compilation failed.
Compilation error: compilation failed; expected "contract 2 _events 1", found "_events 0"
Reason for the error
This error usually occurs when there are multiple events defined in a contract without any mapping to them. The compiler requires that each event have a corresponding function that can handle it.
In your case, you have defined an "event" called "UserCreated", but it does not seem to be associated with any function (for example, "onCreate", "onConnected", etc.). This means that the compiler expects a function to handle this event, but you have not provided one.
How to fix the error
To fix this problem, you need to add a mapping for each event in the contract. For example:
UserCreated( event
memory string _user,
memory address _address
);
You can also use
onEventinstead of an event with no arguments, which will handle the event automatically.
pragma solidity ^0.8.0;
contract market {
function createUser(memory string _user, memory address _address) public {
emit UserCreated(_user, _address);
}
}
Alternatively, you can use
onEvent` with mapping to map events to their corresponding functions.
pragma solidity ^0.8.0;
contract market {
mapping(memory string => event) mapping(address => event) public events;
function createUser(memory string _user, memory address _address) public {
events [UserCreated](_user, _address);
}
}
Conclusion
In conclusion, the “Compile Failed” error when compiling Solid code in a Hardhat project is often caused by missing event mappings. By adding these mappings to your contract, you can resolve the compilation issue and successfully deploy your smart contract to the Ethereum blockchain.
Always remember to refer to the official Solidity documentation and the Ethereum website for more information on event definitions and mapping concepts.