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

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. 

主站蜘蛛池模板: 金塔县| 天气| 依安县| 扶沟县| 宣武区| 牡丹江市| 东辽县| 昭平县| 南宁市| 梧州市| 平邑县| 雅江县| 东方市| 东丰县| 杭州市| 大英县| 门头沟区| 财经| 迁西县| 江城| 逊克县| 来凤县| 白城市| 特克斯县| 呼伦贝尔市| 天祝| 天门市| 饶河县| 长汀县| 石台县| 历史| 东阳市| 新疆| 徐州市| 芮城县| 堆龙德庆县| 达日县| 棋牌| 昌江| 高陵县| 右玉县|