Defining Our Data Structure

Define An 'Event'

Let’s start by defining our smart contract and the information that we want to store on-chain: the creation of a new event by an event organizer and the details associated with that event. We’ll save this in a struct. As a refresher, a struct is similar to a JS object in that it stores related information about an entity. In our case, we’re storing information related to the creation of a new event on our RSVP contract.

contract Web3RSVP { struct CreateEvent { bytes32 eventId; string eventDataCID; address eventOwner; uint256 eventTimestamp; uint256 deposit; uint256 maxCapacity; address[] confirmedRSVPs; address[] claimedRSVPs; bool paidOut; } }

These properties are the properties that each individual event will have on our platform. All of these details will also be stored on-chain.

In general, it’s wise to be picky about the data you store on-chain because it’s expensive to store data on Ethereum. Because of this, you’ll notice that we’re not storing details like the event’s name and event description directly in the struct, but instead we’re storing a reference to an IPFS hash where those details will be stored off-chain. More on this later, but for now just know that’s what eventDataCID is for!

Handling Multiple Events

Because we want our contract to be able to handle the creation of multiple events, we need a mechanism to store and easily look up events by some identifier, like a unique ID. This is what we will use to tell our program which event a user is RSVPing to, since we can assume there will be many.

To do this, we can create a Solidity mapping that maps, or defines a relationship with, a unique eventID to the struct we just defined that is associated with that event.

We’ll use this mapping to make sure we are referencing the correct event when we call functions on that event like RSVPing, confirming attendees, etc.

Inside of our contract and under our struct, we'll define this mapping.

contract Web3RSVP { struct CreateEvent { bytes32 eventId; string eventDataCID; address eventOwner; uint256 eventTimestamp; uint256 deposit; uint256 maxCapacity; address[] confirmedRSVPs; address[] claimedRSVPs; bool paidOut; } mapping(bytes32 => CreateEvent) public idToEvent; }

You've set up the data structure you'll use to hold all of the information related to an event created on your platform as well as setting up a mapping to help you track events via a unique eventID. This is a good place to take a break!

End of Day 3


Writers: Cami