The EventCreator
contract is a Solidity contract that allows users to create, manage, and participate in events. It's designed to handle events with a maximum of 65,000 tickets.
-
Event Creation: Users can create an event by providing details such as the event name, description, location, ticket price, total tickets, deadline, and minimum tickets required for the event to take place.
-
Ticket Purchase: Users can buy tickets for an event. The contract ensures that the event is open, has not ended, and has enough tickets available. It also checks that the user has sufficient funds and has sent enough Ether to cover the cost of the tickets.
-
Event Management: The owner of an event can pause, resume, or cancel the event. If an event is cancelled, all attendees are refunded.
-
Withdraw Funds: The owner of an event can withdraw the funds collected from ticket sales. This can be done either at the end of the event or at the halfway point if the minimum number of tickets has been sold.
-
Fallback Function: The contract includes a fallback function that reverts any transactions that don't match the available functions, preventing Ether from being sent to the contract without a function call.
If you look att this coverage report you can see what line of code that is not covered by the tests.
- A constructor
- Atleast: 1 custom error, one require, one assert, one revert, event, and modifier
- Have a falback function
- Identify and implement atleast three gasoptimzing solution with an explaination.
- Distrubute and verify the contract on etherscan. And provide a link
- Atleast test coverage of 90%
-
Use of
view
andpure
functions: Functions that don't modify the state of the contract should be declared asview
orpure
to save gas. This tells the compiler that the function doesn't modify the state and can be executed locally without sending a transaction to the blockchain. This can save gas by avoiding the cost of writing data to the blockchain. -
Use of
++i
instead ofi++
: In Solidity, using++i
instead ofi++
can save gas. When you usei++
, the value ofi
is first read, then incremented, and then written back to storage. This requires an additional read and write operation, which can cost more gas. On the other hand,++i
increments the value ofi
and returns the new value without the additional read and write operations. -
Use of
if and revert
instead ofRequire
andassert
: Usingif
statements withrevert
can save gas compared to usingrequire
andassert
. Therequire
andassert
statements are more expensive in terms of gas because they perform additional checks and consume more gas. By usingif
statements withrevert
, you can achieve the same functionality with less gas. -
Use of public functions: is used sparingly, as they are more expensive in terms of gas compared to external and internal functions. Public functions include additional logic to handle the input arguments and return values, which can increase the gas cost. By using external and internal functions where possible, you can save gas.