# How Contracts Work

<figure><img src="https://4129755036-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWXVt6DwXFfpY6misTT2A%2Fuploads%2FkqyYQhTqKj8sUNnyEeTj%2Fimage.png?alt=media&#x26;token=265380a2-96a0-4f40-8459-c3bb94df4dcc" alt=""><figcaption></figcaption></figure>

The sequence of events is:

1. Call `QuestFactory.createQuest(rewardType: [erc20]` defined as:

   ```
    function createQuest(
        address rewardTokenAddress_,
        uint256 endTime_,
        uint256 startTime_,
        uint256 totalParticipants_,
        uint256 rewardAmountOrTokenId_,
        string memory contractType_,
        string memory questId_
    )
   ```

   * `rewardTokenAddress_`is the contract address for the ERC20 token reward
   * `endTime` is the end time in unix for the Quest.
   * `startTime` is the start time in unix for the Quest.
   * `totalParticipants` is the total number of accounts that can participate in the Quest.
   * `rewardAmountOrTokenId_` is the reward amount if it's an ERC-20 token (ie. 1 UNI token out of the 1,000 total)
   * `contractType_` will be either an ERC-20 token.
   * `questId` is an internal UUID that connects multiple systems and acts as a universal UUID
2. Transfer rewards to the newly created Quest. You can just transfer in rewards directly.
3. The Quest Factory will keep track of receipts for a given user and quest. There is a finite amount of participants allowed which is calculated by taking the totalRewards / rewardAmountOrTokenId.
4. Execute the start function. This will validate that the Quest is ready for public and upon reaching the effective StartDate, will be ready for use.&#x20;
