以太坊智能合约–简单众筹项目
实验使用remix编译和metamask钱包
pragma solidity ^0.4.0;
contract crowd-funding{//众筹项目
struct funder{
address Funderaddress;//捐赠者地址
uint Tomoney;//捐献了多少笔钱
}
struct needer{
address Neederaddress;//受益者地址
uint goal;//目标资金
uint amount;//已经募集的资金
uint FunderAccount;//捐赠者数量
mapping(uint => funder) map;
}
uint NeederAmount;
mapping(uint=>needer) needmap;
function NewNeeder(address _Neederaddress, uint _goal ){
NeederAmount++;
needmap[NeederAmount] =needer(_Neederaddress,_goal,0,0);
}
function contribute(address _address,uint _NeederAmount) payable{
needer storage _needer = needmap[_NeederAmount];
_needer.amount += msg.value;
_needer.FunderAccount++;
_needer.map[_needer.FunderAccount] = funder( _address, msg.value);
}
function IScomplete(uint _NeederAmount){//转账
needer storage _needer = needmap[_NeederAmount];
if(_needer.amount >= _needer.goal){
_needer.Neederaddress.transfer(_needer.amount);
}
}
}
完成后点击deploy部署 在下面输入相应参数,地址使用任意的本地地址 在value中输入捐赠的数额 图中最后一个为受益者地址
|