- Install Foundry:
curl -L https://foundry.paradigm.xyz | bash;
foundryup
- Test contract:
forge install
forge build
forge test -vvvv --gas-report
- Deploy contract (edit constructor arguments in
EventTicket.s.sol
):
source .env
forge script script/EventTicket.s.sol:EventTicketScript --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv
- Token standard: ERC1155
- Inheritances: ERC1155, Ownable, Pausable, ERC1155Supply
- Each token ID represents one IRL event
State Variable | Data Type | Usage |
---|---|---|
ticketPrice |
mapping(uint => uint) |
Maps tokenId to price |
forSale |
mapping(uint => bool) |
Maps whether tokenId is for sale |
revenueAddress |
address |
The address where ticket fees are sent to |
capacity |
mapping(uint => uint) |
Maximum supply of each tokenId |
Function | Description | Declaration |
---|---|---|
mint(uint, address) |
Mint a token of based on id to recipient address, send fee to revenueAddress |
public payable |
freeMint(uint, address[]) |
Mint an event ticket to a list of specific addresses (e.g. for guest, giveaway) | public onlyOwner |
setRevenueAddress(address) |
Set the revenue address to a new address | public OnlyOwner |
setForSale(uint, bool) |
Toggle the forSale mapping for a tokenId | public OnlyOwner |
setTicketPrice(uint, uint) |
Set the ticket price for the given token id | public OnlyOwner |
setCapacity(uint, uint) |
Set the event capacity for the given token id | public OnlyOwner |
createEvent(uint, uint, uint) |
Create an event by calling setForSale , setTicketPrice , setCapacity |
public OnlyOwner |
Override all the transfer related functions to make it soulbound Also need to expose some internal functions for pausing, etc., use OpenZeppelinContractsWizard for easy setup.
- Create a new event by supplying token id, ticket price, and capacity
- Unpause minting (default should be paused)
- Users mint tickets at ticket price until capacity is full or until we pause
- Owner can also mint tickets to guests or for giveways
- Should create event (only owner)
- Should mint ticket
- Should not mint ticket if msg.value != price
- Should not mint ticket if event is at capacity
- should not mint ticket if id is not for sale
- Should pause/unpause minting (only owner)
- Should mint for free to list of addresses (only owner)
- Should not transfer tokens