"Donation Contract" Example
So in this Post i will be writing a Donation Contract.
The idea is, The Creator Creates the contract.
another person wants to Donate a certain amount of Ether to the Creator.
So from the Remix IDE there are 5 Accounts. im using the first account as the Creator of the Contract and the Last account as the person who will be donating.
After selecting the first account and "Create". Select the Last Account
Once the last account has been selected. add a "Value" like 50 and then click "(fallback)"
the Value is the same as msg.value
Notice from the screenshot about, i have transfer 10 Eth to the Creator.
The idea is, The Creator Creates the contract.
another person wants to Donate a certain amount of Ether to the Creator.
Warning:
Tests done with Remix, i can be the creator and send ether to myself without deduction of my own ether. (Im not sure why it allows this.) ideally if i dont have enough ether, it has to revert back, but it doesnt. (Please help me by commenting Below)
pragma solidity ^0.4.0;
contract DonationAresh {
address creator; //this is Aresh
function DonationAresh() public{
creator = msg.sender;
}
//fall back function that gets an amount of ether and sends to Creator
function () payable public{
safeMoney(msg.value);
}
//send the amount to the creator
function safeMoney(uint amountRaised) private{
creator.send(amountRaised);
}
}
So from the Remix IDE there are 5 Accounts. im using the first account as the Creator of the Contract and the Last account as the person who will be donating.
After selecting the first account and "Create". Select the Last Account
Once the last account has been selected. add a "Value" like 50 and then click "(fallback)"
the Value is the same as msg.value
Notice from the screenshot about, i have transfer 10 Eth to the Creator.
Comments
Post a Comment