- Truffle Quick Start Guide
- Nikhil Bhaskar
- 204字
- 2021-06-25 20:47:34
Writing our first smart contract
To start writing our first smart contract, we must do the following:
- 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.
- 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
- 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.
推薦閱讀
- GPS/GNSS原理與應用(第3版)
- 新一代物聯網架構技術:分層算力網絡
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- 區塊鏈輕松上手:原理、源碼、搭建與應用
- Mastering TypeScript 3
- Learning Swift(Second Edition)
- IPv6網絡切片:使能千行百業新體驗
- 深入理解OpenStack Neutron
- 轉化:提升網站流量和轉化率的技巧
- 一本書讀懂TCP/IP
- 5G非正交多址接入技術:理論、算法與實現
- Qt5 Python GUI Programming Cookbook
- Intelligent Mobile Projects with TensorFlow
- 黑客與反黑工具使用詳解
- 互聯網安全的40個智慧洞見(2018)