Coder Social home page Coder Social logo

jinolacson / event-ticket-exercise-jinolacson Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ca-bootcamp-s19/event-ticket-exercise-jinolacson

1.0 1.0 0.0 105 KB

event-ticket-exercise-jinolacson created by GitHub Classroom

JavaScript 100.00%

event-ticket-exercise-jinolacson's Introduction

Event Ticket Exercise

This directory is a truffle project that contains the required contract, migration and test files. In this exercise you are going to implement the EventTickets.sol and EventTicketsV2.sol contracts.

The contract files contain a framework and comments to help you implement the contract. We have written a set of tests (in javascript) to determine if you implement the contract correctly. As an additional challenge, try writing some Solidity tests in TestEventTicket.sol.

To get started, clone this repo.

This project is configured to connect to a development blockchain running on localhost port 8545. This is the default configuration for Ganache CLI.

You can test your contract by running your development blockchain and then truffle test in the terminal.

If your tests do not pass, modify the contract, recompile, redeploy and retest. Iterate until all of the tests pass.

Event Ticket Requirements:

  • The owner creates the event by setting the # of tickets, description and URL.
  • The event can be viewed to confirm the details set.
  • Tickets can be purchased by indicate the quantity of tickets with the amount of ether they pay the contract.
  • Include the ability to refund the buyer.
  • Include the ability for the owner to end the sale and withdraw the entire balance.

High Level Steps:

  • Create a struct with the following: description, website, tickets, sales, buyers as mapping, isOpen as boolean.
  • Create a constructor and a modifier
  • Create functions: readEvent(), buyTickets(), getRefund(), endSale().

Steps:

  • Create contract structure
  • Create state variables
  • Use a constructor to define the description, the URL, the ticketsAvailable and set isOpen to true.
  • Create a readEvent function that returns the description, the URL, tickets, sales and isOpen.
  • Create a buyTicket function that checks that isOpen is true, the amount sent is greater or equal to the number of tickets x price of the tickets and that the tickets are in stock.
    • allocate the number of tickets to the buyer
    • add the number of tickets to the total sales
    • calculate if any payment change is required and if so, send the change back to the sender
  • Create a getRefund function by:
    • checking the purchaser is valid
    • get the number of tickets purchased
    • subtract this from the total stock
    • remove the buyer from the event mapping
    • transfer the funds back to the sender/purchaser
  • Create an endSale function that when called, will transfer the remaining contract balance to the owner and also set isOpen to false.

event-ticket-exercise-jinolacson's People

Contributors

critesjosh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.