Playboi.eth
10 min readSep 25, 2023

--

Building a Crowdfunding platform Smart Contract Using QuickNode RPC.

Prerequisites;

  • What is a Crowdfunding platform.
  • Key features and components of a Crowdfunding platform Smart Contract.
  • Use cases of a Crowdfunding platform Smart Contract.
  • Writing a Crowdfunding platform Smart contract.
  • Deployment with QuickNode RPC.

WHAT IS A CROWDFUNDING PLATFORM?

A crowdfunding platform is an online platform that allows individuals, businesses, and organizations to raise funds for specific projects, initiatives, or ventures from a large number of people, typically via the internet. It serves as an intermediary, connecting project creators (or fundraisers) with potential backers (or investors).

There are different types of crowdfunding platforms, each serving a specific purpose:

  1. Reward-Based Crowdfunding:
  • In this type, backers contribute funds to a project in exchange for non-financial rewards, such as early access to a product, special merchandise, or other incentives related to the project.

2. Equity-Based Crowdfunding:

  • Equity crowdfunding involves backers investing in a project or business in exchange for equity ownership or shares. If the project succeeds, investors may receive a portion of the profits.

3. Donation-Based Crowdfunding:

  • This type allows backers to make contributions to a project without expecting any financial return. It is often used for charitable or philanthropic causes.

4. Debt-Based Crowdfunding (Peer-to-Peer Lending):

  • Backers lend money to a project or individual, expecting to be repaid with interest over time.

5. Real Estate Crowdfunding:

  • This focuses specifically on real estate projects. Investors contribute funds towards a real estate venture, and in return, they may receive a share of rental income or profits from property sales.

6. Blockchain-Based Crowdfunding (Initial Coin Offerings — ICOs):

  • Utilizing blockchain technology, ICOs allow startups to raise capital by issuing tokens or cryptocurrencies to backers. These tokens may represent ownership in a project or have specific utility within a platform.

They provide an accessible and efficient way for entrepreneurs, artists, nonprofits, and others to fund their ventures or projects. They leverage the collective power of a large number of individuals, often providing opportunities for backers to support causes or ideas they believe in.

KEY FEATURES AND COMPONENTS OF A CROWDFUNDING PLATFORM SMART CONTRACT.

  1. Project Registration:
  • Allows project creators to register their projects on the platform. This includes providing details about the project, funding goal, duration of the campaign, and any rewards or incentives for backers.

2. Funding Mechanism:

  • Defines the method through which backers can contribute funds to a project. This can involve accepting cryptocurrencies, fiat currency, or other payment methods supported by the platform.

3. Funding Goal and Deadline:

  • Sets a target amount that the project creator aims to raise. The campaign is considered successful if it reaches or exceeds this goal within a specified timeframe.

4. Escrow Services:

  • Utilizes an escrow system to securely hold funds until the campaign reaches its goal or deadline. Once the goal is met, the funds are released to the project creator. If not, they may be returned to the backers.

5. Refund Mechanism:

  • Specifies conditions under which backers can request a refund, such as if the campaign fails to reach its funding goal within the allotted time.

6. Reward Distribution:

  • Defines how project creators distribute rewards or incentives to backers based on their level of contribution. This may include digital products, early access, or other perks.

7. Smart Contract Governance:

  • Includes mechanisms for project creators to manage and update their campaigns. This could involve editing project details, extending the campaign duration, or canceling a campaign (under specific circumstances).

8. Backer Authentication and Verification:

  • Ensures that backers are eligible and authorized to participate in a campaign. This may involve verifying identities or conducting Know Your Customer (KYC) checks.

9. Project Visibility and Discovery:

  • Provides a platform interface for users to browse and discover projects. It may include features like search, filters, and categories to help users find projects of interest.

10. User Wallet Integration:

  • Allows users to connect their digital wallets to the platform for easy contributions and receipt of rewards or refunds.

11. Reporting and Analytics:

  • Offers tools for project creators to track the progress of their campaigns, view contribution history, and generate reports on campaign performance.

12. Communication Tools:

  • Facilitates communication between project creators and backers, allowing them to ask questions, receive updates, and address concerns.

13. Dispute Resolution:

  • Includes a mechanism to handle disputes between project creators and backers, providing a fair resolution process.

14. Compliance and Legal Considerations:

  • Ensures that the platform and campaigns adhere to legal and regulatory requirements, which may vary depending on the jurisdiction.

15. Security Measures:

  • Implements security protocols to protect against potential vulnerabilities or attacks, safeguarding the funds and data of users.

USECASES OF A CROWDFUNDING PLATFORM SMART CONTRACT.

  1. Entrepreneurial Ventures:
  • Entrepreneurs and startups can use crowdfunding platforms to raise seed capital for launching new businesses or developing innovative products and services.

2. Creative Projects:

  • Artists, musicians, filmmakers, and writers can seek funding for creative endeavors, such as producing albums, making films, publishing books, or creating artwork.

3. Technology and Innovation:

  • Tech innovators and inventors can showcase their prototypes or concepts and gather funding to bring their innovations to market.

4. Social Causes and Nonprofits:

  • Nonprofit organizations and individuals working for social or environmental causes can use crowdfunding to raise funds for specific projects or campaigns.

5. Real Estate Development:

  • Developers and real estate professionals can utilize crowdfunding to finance property development projects, allowing investors to own fractional shares of the property.

6. Medical Research and Health Initiatives:

  • Researchers and healthcare professionals can use crowdfunding to fund medical studies, clinical trials, and initiatives aimed at finding cures or improving healthcare services.

7. Community Projects:

  • Communities can come together to fund local initiatives, such as building parks, renovating public spaces, or organizing events for the benefit of the community.

8. Education and Skill-building:

  • Individuals, educators, or organizations can seek funding for educational programs, courses, workshops, or skill-building initiatives.

9. Environmental Projects:

  • Initiatives focused on conservation, sustainability, or environmental protection can use crowdfunding to fund projects like reforestation efforts, wildlife preservation, or clean energy solutions.

10. Innovative Gadgets and Technology:

  • Inventors and tech enthusiasts can present prototypes of gadgets, software, or hardware projects to gather funding for production and development.

WRITING A CROWDFUNDING PLATFORM SMART CONTRACT.

Hey, enough of the fundamentals, its time to go technical!

Below is a Crowdfunding platform smart contract code;

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract CrowdfundingPlatform {
struct Project {
address creator;
uint256 goal;
uint256 deadline;
uint256 totalContributions;
bool projectActive;
}

mapping(uint256 => Project) public projects;
mapping(uint256 => mapping(address => uint256)) public contributions;

address public owner;
uint256 public nextProjectId = 1;
uint256 public fractionalDecimal = 3;

event ProjectCreated(uint256 indexed projectId, address indexed creator, uint256 goal, uint256 deadline);
event ContributionMade(uint256 indexed projectId, address indexed contributor, uint256 amount);
event ProjectFunded(uint256 indexed projectId);

modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can call this function");
_;
}

constructor() {
owner = msg.sender;
}

function createProject(uint256 _goal, uint256 _deadline) external {
require(_goal > 0, "Goal must be greater than zero");
require(_deadline > block.timestamp, "Deadline must be in the future");

projects[nextProjectId] = Project({
creator: msg.sender,
goal: _goal,
deadline: _deadline,
totalContributions: 0,
projectActive: true
});

emit ProjectCreated(nextProjectId, msg.sender, _goal, _deadline);
nextProjectId++;
}

function contributeToProject(uint256 _projectId, uint256 _amount) external {
Project storage project = projects[_projectId];
require(project.projectActive, "Project is not active");
require(block.timestamp <= project.deadline, "Project deadline has passed");
require(_amount > 0, "Contribution amount must be greater than zero");

contributions[_projectId][msg.sender] += _amount;
project.totalContributions += _amount;

emit ContributionMade(_projectId, msg.sender, _amount);

if (project.totalContributions >= project.goal) {
project.projectActive = false;
emit ProjectFunded(_projectId);
}
}

function withdrawFunds(uint256 _projectId) external onlyOwner {
Project storage project = projects[_projectId];
require(!project.projectActive, "Project is still active");
require(project.totalContributions >= project.goal, "Project did not reach its goal");

uint256 totalContributions = project.totalContributions;
address creator = project.creator;

project.totalContributions = 0;
for (uint256 i = 1; i <= nextProjectId; i++) {
delete contributions[_projectId][creator];
}

payable(creator).transfer(totalContributions);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract CrowdfundingPlatform {
  • This is the contract definition. It's named CrowdfundingPlatform.
struct Project {
address creator;
uint256 goal;
uint256 deadline;
uint256 totalContributions;
bool projectActive;
}
  • Here, a struct named Project is defined. It represents a crowdfunding project and contains the following properties:
  • creator: Address of the project creator.
  • goal: The funding goal of the project.
  • deadline: The timestamp when the project's crowdfunding period ends.
  • totalContributions: Total amount contributed to the project.
  • projectActive: A boolean indicating if the project is still open for contributions.
mapping(uint256 => Project) public projects;
mapping(uint256 => mapping(address => uint256)) public contributions;
  • These are mappings that associate project IDs with their respective Project structures and contributions. projects maps project IDs to Project structures, and contributions maps project IDs to contributors' addresses and their contribution amounts.
address public owner;
uint256 public nextProjectId = 1;
uint256 public fractionalDecimal = 3;
  • These are state variables:
  • owner: Address of the owner (deployer) of the contract.
  • nextProjectId: A counter to keep track of the next available project ID.
  • fractionalDecimal: An integer indicating the level of fractional ownership (in this case, it's set to 3).
event ProjectCreated(uint256 indexed projectId, address indexed creator, uint256 goal, uint256 deadline);
event ContributionMade(uint256 indexed projectId, address indexed contributor, uint256 amount);
event ProjectFunded(uint256 indexed projectId);
  • These are events that will be emitted during certain contract actions. They provide a way for external systems to listen for specific activities on the contract.
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can call this function");
_;
}
  • This is a modifier named onlyOwner. It restricts certain functions to be callable only by the owner of the contract.
constructor() {
owner = msg.sender;
}
  • This is the constructor function. It sets the owner to the address that deployed the contract.
function createProject(uint256 _goal, uint256 _deadline) external {
require(_goal > 0, "Goal must be greater than zero");
require(_deadline > block.timestamp, "Deadline must be in the future");

projects[nextProjectId] = Project({
creator: msg.sender,
goal: _goal,
deadline: _deadline,
totalContributions: 0,
projectActive: true
});

emit ProjectCreated(nextProjectId, msg.sender, _goal, _deadline);
nextProjectId++;
}
  • This function allows anyone to create a new crowdfunding project. It requires a funding goal (_goal) and a deadline (_deadline) in timestamps. It then creates a new Project struct and emits a ProjectCreated event.
function contributeToProject(uint256 _projectId, uint256 _amount) external {
Project storage project = projects[_projectId];
require(project.projectActive, "Project is not active");
require(block.timestamp <= project.deadline, "Project deadline has passed");
require(_amount > 0, "Contribution amount must be greater than zero");

contributions[_projectId][msg.sender] += _amount;
project.totalContributions += _amount;

emit ContributionMade(_projectId, msg.sender, _amount);

if (project.totalContributions >= project.goal) {
project.projectActive = false;
emit ProjectFunded(_projectId);
}
}
  • This function allows contributors to contribute to a specific project (_projectId). It checks if the project is active and if the deadline has not passed. It also ensures the contribution amount is valid. If all conditions are met, it updates the contributions mapping and the project's total contributions. If the funding goal is met, it marks the project as inactive and emits a ProjectFunded event.
function withdrawFunds(uint256 _projectId) external onlyOwner {
Project storage project = projects[_projectId];
require(!project.projectActive, "Project is still active");
require(project.totalContributions >= project.goal, "Project did not reach its goal");

uint256 totalContributions = project.totalContributions;
address creator = project.creator;

project.totalContributions = 0;
for (uint256 i = 1; i <= nextProjectId; i++) {
delete contributions[_projectId][creator];
}

payable(creator).transfer(totalContributions);
}
}
  • This function allows the owner to withdraw funds from a project once it's no longer active and has reached its funding goal. It transfers the total contributions to the project creator.

This contract enables the creation and management of crowdfunding projects, allowing contributors to fund projects and project creators to withdraw funds once their goals are met. This contract also maintains transparency through events and public mappings.

Lets write this code in our REMIX IDE.

DEPLOYMENT WITH QUICKNODE RPC.

STEP 1.

Create a new sepolia node on QuickNode. You would have to navigate to the QuickNode Dashboard and click on “Create”.

Then after, make sure you click on the Ethereum chain. Check a screenshoot below;

Click on Sepolia:

Then click on ‘continue’ to proceed. Finally click on ‘create endpoint’ to get your Sepolia url.

STEP 2.

Click on “Add network”. Follow the instructions on how to add the RPC url to your wallet browser.

Click on “Add network manually”.

STEP 3.

Enter a name (any) since your using QuickNode , you can use ‘QKN’ copy/paste your Web3 endpoint (be sure to include the “/” at the end!), enter ChainID and click “Save”.

We are using Sepolia Teastnet, so its advisable to use sepolia chain ID, Which is ‘11155111’.

Finally, you would get the below result.

Perfect! We are almost finished, Now we would be requesting some Eth from Sepolia Testnet so as to be able to deploy our smart contract.

STEP 4.

Now to get gas fees, we are going to be using https://faucet.quicknode.com/drip. Below is the procedure.

Then connect wallet and get some Eth.

After doing this, you would get the result below:

With this, we are ready to deploy our crowdfunding platform smart contract.

Deploying smart contract code to sepolia testnet.

Click on ‘confirm’ to finalize transactions.

Conclusion

Congratulations on successfully creating your very own Crowdfunding platform Smart contract on the Ethereum network! .

Subscribe to QuickNode newsletter for more articles and guides on Ethereum. If you have any feedback, feel free to reach out to us via Twitter. You can always chat with us on our Discord community server, featuring some of the coolest developers you’ll ever meet :)

--

--

Playboi.eth

22y/o smart contract engineer. Advocate @graphprotocol, Ambassador @quicknode, Contributor @girscriptsoc . prev @web3_Nados, @blockchain