Skip to content

Instantly share code, notes, and snippets.

@carloscarvallo
Created December 22, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carloscarvallo/984e3d4471887e4c3bdf700a75571210 to your computer and use it in GitHub Desktop.
Save carloscarvallo/984e3d4471887e4c3bdf700a75571210 to your computer and use it in GitHub Desktop.
Crowd funding smart contract example with optimized variables to minimize Gas
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract CrowdFunding {
string public id;
string public name;
string public description;
address payable public author;
string public state = 'Opened';
uint public funds;
uint public fundraisingGoal;
constructor(string memory _id, string memory _name, string memory _description, uint _fundraisingGoal) {
id = _id;
name = _name;
description = _description;
fundraisingGoal = _fundraisingGoal;
author = payable(msg.sender);
}
function fundProject() public payable {
author.transfer(msg.value);
funds += msg.value;
}
function changeProjectState(string calldata newState) public {
state = newState;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment