官术网_书友最值得收藏!

Writing our first smart contract

To start writing our first smart contract, we must do the following:

  1. Head over to https://github.com/PacktPublishing/Truffle-Quick-Start-Guide and clone it. That's where the fully working projects for each chapter are. You can git clone the entire repository to keep as a reference when working through this chapter.
  2. To ensure we follow proper formatting and camel-case naming conventions, replace Migrations.sol with the contents of https://github.com/PacktPublishing/Truffle-Quick-Start-Guide/blob/master/chapter1/contracts/Migrations.sol.
    • Unfortunately, the original Migrations.sol file is poorly formatted and uses snake-case variable naming, so this step is necessary
  1. Create a new file under /contracts, called TaskMaster.sol.
  • This is where your logic for instantiating your to-do list contract and rewarding a doer will live.

Start by creating the constructor, and define an array to hold the current TodoCoin balances of everyone in the contract:

pragma solidity ^0.4.17;


contract TaskMaster {
mapping (address => uint) public balances; // balances of everyone

function TaskMaster() public {
balances[msg.sender] = 10000;
}
}

Notice how we hardcode a value of 10000 to the initiator of this contract. Let's go with this for now. We can think of this to mean that the initiator of the TaskMaster contract starts off with a balance of 10000 TodoCoins. 

主站蜘蛛池模板: 丹凤县| 博罗县| 郸城县| 叙永县| 楚雄市| 科技| 巢湖市| 禹城市| 呼玛县| 牙克石市| 罗城| 六盘水市| 蒙自县| 定安县| 东山县| 阿鲁科尔沁旗| 邓州市| 壶关县| 临安市| 望都县| 梓潼县| 曲沃县| 施秉县| 文登市| 榆树市| 修文县| 五大连池市| 康保县| 奉贤区| 施秉县| 玉门市| 东丰县| 封丘县| 定襄县| 开平市| 阜康市| 宜兴市| 芜湖市| 东源县| 寿光市| 遂溪县|