- 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.
推薦閱讀
- CorelDRAW X6 中文版圖形設計實戰從入門到精通
- 物聯網(IoT)基礎:網絡技術+協議+用例
- EDA技術與VHDL編程
- SOA用戶指南
- 異構基因共表達網絡的分析方法
- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- 走進物聯網
- 網絡的琴弦:玩轉IP看監控
- Getting Started with WebRTC
- 物聯網技術與應用
- CCNP TSHOOT(642-832)認證考試指南
- SAE原理與網絡規劃
- React Cookbook
- 深入理解Nginx:模塊開發與架構解析
- Microsoft Power Platform Enterprise Architecture