Created
December 5, 2022 15:22
-
-
Save ajays97/85624dd5f29b4f16d308d0fa41490a1b to your computer and use it in GitHub Desktop.
Solidity Smart Contract to manage a DAO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.0; | |
contract LaunchpadDAO { | |
// The address of the owner of this contract | |
address public owner; | |
// The list of projects currently managed by this DAO | |
Project[] public projects; | |
// The struct representing a project | |
struct Project { | |
// The address of the creator of this project | |
address creator; | |
// The name of the project | |
string name; | |
// The amount of funding raised for this project | |
uint256 funding; | |
// The minimum amount of funding required for this project to be considered successful | |
uint256 fundingGoal; | |
} | |
// The constructor of the contract, called when it is deployed to the blockchain | |
constructor() public { | |
// Set the owner of this contract to the address that deployed it | |
owner = msg.sender; | |
} | |
// A function to create a new project | |
function createProject(string memory _name, uint256 _fundingGoal) public { | |
// Create a new project and add it to the list of projects | |
projects.push(Project(msg.sender, _name, 0, _fundingGoal)); | |
} | |
// A function to contribute funds to a project | |
function contribute(uint256 _projectId, uint256 _amount) public { | |
// Get the project with the given ID | |
Project storage project = projects[_projectId]; | |
// Add the contributed funds to the project's funding | |
project.funding += _amount; | |
} | |
// A function to withdraw funds from a successful project | |
function withdraw(uint256 _projectId) public { | |
// Get the project with the given ID | |
Project storage project = projects[_projectId]; | |
// Ensure that the caller is the creator of the project | |
require(project.creator == msg.sender, "Only the creator of the project can withdraw funds"); | |
// Ensure that the project has reached its funding goal | |
require(project.funding >= project.fundingGoal, "The project has not reached its funding goal"); | |
// Transfer the funds raised to the project creator | |
project.creator.transfer(project.funding); | |
// Reset the funding to 0 | |
project.funding = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment