|
1 | | -# Crowdfunding Contract (StarkNet) |
| 1 | +# Starknet Crowdfunding Platform |
2 | 2 |
|
3 | | -This StarkNet contract implements a crowdfunding mechanism where users can contribute to a campaign with any ERC20 tokens(contract addresss is needed to pass to the contract). Funds are withdrawn to a designated grantee address once the target amount is reached or the campaign deadline is passed. |
| 3 | +A decentralized crowdfunding platform built on StarkNet, enabling users to create and participate in fundraising campaigns using ERC20 tokens. The platform consists of a Cairo smart contract for on-chain logic and a Next.js frontend for user interaction. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 |
|
7 | | -* Users can donate ERC20 tokens to the contract. |
8 | | -* Contract owner can withdraw funds to the grantee address. |
9 | | -* Contract owner can reset the contract for a new campaign (after target is met or deadline passes and all funds are withdrawn). |
10 | | -* Supports any ERC20 token on starknet(default STRK) |
| 7 | +### Smart Contract |
| 8 | +* Support for any ERC20 token on StarkNet (currently UI supports STRK and ETH) |
| 9 | +* Secure fund management with ownership controls |
| 10 | +* Deadline-based campaign management |
| 11 | +* Flexible campaign reset functionality |
| 12 | +* Transparent fund tracking and withdrawal system |
| 13 | + |
| 14 | +### Frontend Interface |
| 15 | +* Modern, responsive UI built with Next.js and Tailwind CSS |
| 16 | +* Real-time campaign progress tracking |
| 17 | +* Interactive donation interface |
| 18 | +* Countdown timer for campaign deadline |
| 19 | +* Dark/Light mode support |
| 20 | +* Owner-specific controls for campaign management |
| 21 | + |
| 22 | +## Project Structure |
| 23 | + |
| 24 | +``` |
| 25 | +scaffold-stark-crowd-funding/ |
| 26 | +├── packages/ |
| 27 | +│ ├── nextjs/ # Frontend application |
| 28 | +│ │ ├── app/ # Next.js pages and components |
| 29 | +│ │ ├── components/ # Reusable UI components |
| 30 | +│ │ └── hooks/ # Custom React hooks |
| 31 | +│ └── snfoundry/ # Smart contract |
| 32 | +│ └── contracts/ # Cairo contract files |
| 33 | +``` |
| 34 | + |
| 35 | +## Prerequisites |
| 36 | + |
| 37 | +* Node.js (v16 or higher) |
| 38 | +* Yarn package manager |
| 39 | +* Scarb (for Cairo contract development) |
| 40 | +* StarkNet wallet (e.g., ArgentX, Braavos) |
| 41 | + |
| 42 | +## Getting Started |
| 43 | + |
| 44 | +1. Clone the repository: |
| 45 | + ```bash |
| 46 | + git clone https://github.com/yourusername/scaffold-stark-crowd-funding.git |
| 47 | + cd scaffold-stark-crowd-funding |
| 48 | + ``` |
| 49 | + |
| 50 | +2. Install dependencies: |
| 51 | + ```bash |
| 52 | + yarn install |
| 53 | + ``` |
| 54 | + |
| 55 | +3. Compile the smart contract: |
| 56 | + ```bash |
| 57 | + cd packages/snfoundry/contracts |
| 58 | + scarb build |
| 59 | + ``` |
| 60 | + |
| 61 | +4. Run contract tests: |
| 62 | + ```bash |
| 63 | + scarb test |
| 64 | + ``` |
| 65 | + |
| 66 | +5. Deploy the contract: |
| 67 | + ```bash |
| 68 | + yarn deploy --network {NETWORK_NAME} # "sepolia" or "mainnet", defaults to "devnet" |
| 69 | + ``` |
| 70 | + |
| 71 | +6. Start the frontend development server: |
| 72 | + ```bash |
| 73 | + cd packages/nextjs |
| 74 | + yarn dev |
| 75 | + ``` |
| 76 | + |
| 77 | +## Smart Contract Interface |
| 78 | + |
| 79 | +The contract implements the `IFund` interface with the following functions: |
| 80 | + |
| 81 | +### Read Functions |
| 82 | +* `get_fund_balance`: Get current campaign balance |
| 83 | +* `get_fund_target`: Get campaign funding target |
| 84 | +* `get_fund_description`: Get campaign description |
| 85 | +* `get_deadline`: Get campaign end timestamp |
| 86 | +* `get_token_symbol`: Get fundraising token symbol |
| 87 | +* `get_token_address`: Get fundraising token contract address |
| 88 | +* `get_owner`: Get contract owner address |
| 89 | +* `get_active`: Get campaign active status |
| 90 | + |
| 91 | +### Write Functions |
| 92 | +* `fund_to_contract`: Contribute tokens to the campaign |
| 93 | +* `withdraw_funds`: Withdraw funds to grantee (owner only) |
| 94 | +* `reset_fund`: Reset campaign with new parameters (owner only) |
| 95 | +* `set_active`: Toggle campaign active status (owner only) |
| 96 | + |
| 97 | +## Frontend Features |
| 98 | + |
| 99 | +### Campaign Information |
| 100 | +* Real-time display of: |
| 101 | + - Campaign description |
| 102 | + - Current balance |
| 103 | + - Funding target |
| 104 | + - Progress percentage |
| 105 | + - Remaining time |
| 106 | + - Token symbol |
| 107 | + |
| 108 | +### User Interface |
| 109 | +* Wallet connection integration |
| 110 | +* Donation input with token selection |
| 111 | +* Progress bar visualization |
| 112 | +* Countdown timer |
| 113 | +* Responsive design for all devices |
| 114 | +* Dark/Light theme support |
| 115 | + |
| 116 | +### Owner Controls |
| 117 | +* Campaign activation/deactivation |
| 118 | +* Fund withdrawal management |
| 119 | +* Campaign reset functionality |
11 | 120 |
|
12 | | -## Usage |
13 | | - |
14 | | -1. Deploy the contract with the desired campaign details: |
15 | | - * `token` (optional, defaults to STRK token address): Contract address of the ERC20 token used for funding. |
16 | | - * `grantee_address`: Address of the beneficiary who will receive the raised funds. |
17 | | - * `fund_target`: Target amount to raise in the crowdfunding campaign. |
18 | | - * `fund_description`: Description of the campaign (English only). |
19 | | - * `deadline`: Unix timestamp representing the campaign end date. |
20 | | - * `initial_owner`: Address of the initial contract owner. |
21 | | - |
22 | | -2. Users can call the `fund_to_contract` function to donate STRK tokens to the contract. |
23 | | - |
24 | | -3. The contract owner can call the `withdraw_funds` function to withdraw all collected funds to the grantee address when the target is met or the deadline is reached. |
25 | | - |
26 | | -4. After a successful campaign or withdrawal, the contract owner can call the `reset_fund` function to set up a new campaign with different details. This requires the previous campaign to be completed (target met or deadline passed) and all funds withdrawn. |
| 121 | +## Events |
27 | 122 |
|
28 | | -## Interface |
| 123 | +The contract emits the following events: |
29 | 124 |
|
30 | | -The contract implements the `IFund` interface which defines the following functions: |
| 125 | +* `OwnableEvent`: Ownership management events |
| 126 | +* `SelfDestructed`: Contract self-destruction event |
| 127 | +* `Transfer`: Successful token transfer event |
| 128 | +* `TransferFailed`: Failed transfer event |
| 129 | +* `ResetFund`: Campaign reset event |
| 130 | +* `ActiveChanged`: Campaign status change event |
31 | 131 |
|
32 | | -* `get_fund_balance`: Returns the current balance of the contract in STRK tokens. |
33 | | -* `get_fund_target`: Returns the target funding amount for the campaign. |
34 | | -* `get_fund_description`: Returns the description of the crowdfunding campaign. |
35 | | -* `get_deadline`: Returns the Unix timestamp for the campaign deadline. |
36 | | -* `fund_to_contract`: Allows users to donate STRK tokens to the contract. |
37 | | -* `withdraw_funds`: Allows the contract owner to withdraw all collected funds to the grantee address. |
38 | | -* `reset_fund`: Allows the contract owner to reset the contract for a new campaign. |
| 132 | +## Security Considerations |
39 | 133 |
|
40 | | -## Events |
| 134 | +* Owner-only access control for sensitive functions |
| 135 | +* Deadline enforcement for campaign lifecycle |
| 136 | +* Safe token transfer handling |
| 137 | +* Input validation for all user interactions |
| 138 | +* Proper error handling and event emission |
41 | 139 |
|
42 | | -The contract emits several events: |
| 140 | +## Dependencies |
43 | 141 |
|
44 | | -* `OwnableEvent`: Events related to contract ownership management (inherited from OwnableComponent). |
45 | | -* `SelfDestructed`: Emitted when the contract is self-destructed, indicating the recipient address and remaining funds. |
46 | | -* `Transfer`: Emitted when a successful token transfer occurs (e.g., user donation). |
47 | | -* `TransferFailed`: Emitted when a token transfer fails. |
48 | | -* `ResetFund`: Emitted when the contract is reset for a new campaign, including details of the new campaign. |
| 142 | +### Smart Contract |
| 143 | +* OpenZeppelin Contracts (Cairo) |
| 144 | + - Ownable component |
| 145 | + - ERC20 interface |
49 | 146 |
|
50 | | -## Dependencies |
| 147 | +### Frontend |
| 148 | +* Next.js 13+ |
| 149 | +* React |
| 150 | +* Tailwind CSS |
| 151 | +* scaffold-stark hooks |
| 152 | +* StarkNet.js |
51 | 153 |
|
52 | | -* OpenZeppelin Ownable: Provides ownership management functionality. |
53 | | -* OpenZeppelin ERC20: Provides interaction with ERC20 tokens. |
| 154 | +## Contributing |
54 | 155 |
|
55 | | -## Deployment and Interaction (Example using starkli) |
| 156 | +Contributions are welcome! Please feel free to submit a Pull Request. |
56 | 157 |
|
57 | | -```bash |
58 | | -# Compile the contract |
59 | | -cd packages/snfoundry/contracts |
60 | | -scarb build |
61 | | -# Run the contract test |
62 | | -scarb test |
| 158 | +## License |
63 | 159 |
|
64 | | -# Deploy the contract |
65 | | -yarn deploy --network {NETWORK_NAME} //"sepolia" or "mainnet", defaults to "devnet" |
| 160 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments