- Truffle Quick Start Guide
- Nikhil Bhaskar
- 174字
- 2021-06-25 20:47:34
Creating a reward method
This will be invoked by the owner to reward a doer for their successful completion of a task:
pragma solidity ^0.4.17;
contract TaskMaster {
mapping (address => uint) public balances; // balances of everyone
address public owner; // owner of the contract
function TaskMaster() public {
owner = msg.sender;
balances[msg.sender] = 10000;
}
function reward(address doer, uint rewardAmount)
public
returns(bool sufficientFunds)
{
balances[msg.sender] -= rewardAmount;
balances[doer] += rewardAmount;
return sufficientFunds;
}
}
This function accepts the following:
- an address for the doer
- an integer amount for their reward
We are almost there—we need to add some necessary security touches.
Notice how we are not performing a real transfer of ETH, but rather we simply decrement the balance of the owner and increment the balance of the doer. The reason we don't perform a real transfer here is because we simply hard-coded a balance value of 10000 and made up a token called TodoCoin. Remember, our goal in this chapter is to get a fully functioning Dapp using Truffle.
推薦閱讀
- Aptana Studio Beginner's Guide
- 微商之道
- 解析QUIC/HTTP3:未來(lái)互聯(lián)網(wǎng)的基石
- EDA技術(shù)與VHDL編程
- 物聯(lián)網(wǎng)網(wǎng)絡(luò)安全及應(yīng)用
- 工業(yè)控制網(wǎng)絡(luò)安全技術(shù)與實(shí)踐
- JBoss EAP6 High Availability
- 正在爆發(fā)的互聯(lián)網(wǎng)革命
- 大話社交網(wǎng)絡(luò)
- Mastering TypeScript 3
- Getting Started with Grunt:The JavaScript Task Runner
- 中國(guó)互聯(lián)網(wǎng)發(fā)展報(bào)告2018
- 圖解手機(jī)元器件維修技巧
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實(shí)戰(zhàn)
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實(shí)戰(zhàn)指南