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

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. 

主站蜘蛛池模板: 奉新县| 东安县| 沁水县| 习水县| 五寨县| 泰宁县| 象州县| 海晏县| 河北省| 徐州市| 马山县| 靖远县| 万安县| 扶绥县| 犍为县| 张家界市| 洪雅县| 钦州市| 安徽省| 托克托县| 额济纳旗| 穆棱市| 政和县| 龙海市| 连江县| 昌黎县| 中卫市| 荆州市| 沛县| 兴安盟| 淮北市| 庆城县| 松溪县| 波密县| 沂水县| 杂多县| 池州市| 安国市| 招远市| 句容市| 马龙县|