Skip to content

Refactor event ticket Contract#66

Open
chauhan-varun wants to merge 2 commits into
nishantharkut:mainfrom
chauhan-varun:refactorEventTicket
Open

Refactor event ticket Contract#66
chauhan-varun wants to merge 2 commits into
nishantharkut:mainfrom
chauhan-varun:refactorEventTicket

Conversation

@chauhan-varun
Copy link
Copy Markdown
Contributor

EventTicketNFT Contract Update

Closes #65

🔄 Contract Changes

Key Improvements Made:

  1. Enhanced Documentation: Added comprehensive NatSpec comments
  2. State Variable Naming: Updated to follow Solidity best practices with s_ prefix
  3. Custom Error Handling: Implemented custom errors for better gas efficiency
  4. Input Validation: Added proper validation for addresses and token URIs
  5. New Getter Function: Added getTokenCounter() function for transparency

Contract Features:

  • Custom Errors: EventTicketNFT__InvalidOwnerAddress, EventTicketNFT__InvalidRecipientAddress, EventTicketNFT__EmptyTokenURI
  • Enhanced Validation: Checks for zero addresses and empty URIs
  • Improved State Management: Two separate counters for different minting functions
  • Better Events: Consistent TicketMinted event emission

📁 Files Updated

Smart Contract

  • contracts/EventTicketNFT.sol - Updated with enhanced features

Generated Artifacts

  • artifacts/contracts/EventTicketNFT.sol/EventTicketNFT.json - New ABI generated
  • server/abi/EventTicketNFT.json - Updated ABI for backend
  • client/src/artifacts/contracts/EventTicketNFT.sol/EventTicketNFT.json - Updated ABI for frontend

Frontend Updates

  • client/src/lib/ticketNFT.ts - Enhanced with new functions and error handling
  • client/src/components/MintTicket.tsx - Improved error messages and validation
  • client/src/hooks/useTokenCounter.ts - New hook for token counter
  • client/src/components/TokenCounterDisplay.tsx - New component to display token count

Backend Updates

  • server/listeners/mintListener.js - Updated ABI path for consistency
  • ✅ Event listeners remain compatible with existing TicketMinted event

🚀 New Features Available

Frontend Functions:

// Existing function with enhanced error handling
mintTicket(tokenURI: string): Promise<string>

// New function for getting token counter
getTokenCounter(): Promise<number>

// New function for owner-only minting
safeMint(to: string, uri: string): Promise<string>

React Components:

// New hook for token counter
const { counter, loading, error, refresh } = useTokenCounter();

// New display component
<TokenCounterDisplay className="my-custom-class" />

🔗 Integration Notes

  • All existing functionality remains intact
  • Event listeners continue to work with the same TicketMinted event
  • Frontend components have backward compatibility
  • Enhanced error messages provide better UX
  • New getTokenCounter() function allows for better UI updates

@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 29, 2025

@chauhan-varun is attempting to deploy a commit to the nishantharkut's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Event Ticket Contracts for Solidity Best Practices, Gas Efficiency, and Readability

1 participant