A decentralized donation application built on AElf blockchain that allows users to create and manage fundraising campaigns. Users can create campaigns with specific goals and time frames, and others can donate to these campaigns using ELF tokens.
- Create donation campaigns with title, description, target amount, and duration
- Donate ELF tokens to active campaigns
- View campaign details including current amount raised and donor list
- Automatic campaign state management based on start and end times
- Token approval and transfer handling
donation/
├── src/ # Smart contract source code
│ ├── Donation.csproj # Contract project file
│ ├── DonationApp.cs # Main contract implementation
│ └── Protobuf/ # Protocol buffer definitions
├── test/ # Unit tests
│ ├── DonationDAppTests.csproj
│ └── DonationDAppTests.cs
- .NET SDK 8.0 or later
- AElf Contract Development Kit
- Node.js and npm (for deploying to testnet/mainnet)
- AElf CLI tools (
npm install -g aelf-command
)
Build the contract:
cd donation/src
dotnet build
- Set your environment variables:
export WALLET_ADDRESS="your_wallet_address"
export WALLET_PASSWORD="your_wallet_password"
export CONTRACT_PATH="./src/bin/Debug/net8.0/Donation.dll"
- Start your local AElf node
- Deploy the contract:
aelf-deploy -a $WALLET_ADDRESS -p $WALLET_PASSWORD -c $CONTRACT_PATH -e http://127.0.0.1:8000
- Deploy to testnet:
aelf-deploy -a $WALLET_ADDRESS -p $WALLET_PASSWORD -c $CONTRACT_PATH -e https://tdvw-test-node.aelf.io/
aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Initialize
aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io CreateCampaign \
-j '{"title":"Campaign Title","description":"Description","targetAmount":1000000000,"startTime":"2024-01-10","endTime":"2024-02-10"}'
# First approve token spending
aelf-command send $TOKEN_CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Approve \
-j '{"spender":"'$CONTRACT_ADDRESS'","symbol":"ELF","amount":1000000000}'
# Then donate
aelf-command send $CONTRACT_ADDRESS -a $WALLET_ADDRESS -p $WALLET_PASSWORD -e https://tdvw-test-node.aelf.io Donate \
-j '{"campaignId":"'$CAMPAIGN_ID'","amount":1000000000}'
aelf-command call $CONTRACT_ADDRESS -a $WALLET_ADDRESS -e https://tdvw-test-node.aelf.io GetCampaign \
-j '{"value":"'$CAMPAIGN_ID'"}'
The project includes comprehensive unit tests covering:
- Contract initialization
- Campaign creation and validation
- Donation functionality
- Campaign state management
- Query operations
Run tests with coverage:
cd test
dotnet test
This project is licensed under the MIT License.