pragma solidity >=0.4.17 <0.6.0; import "./SafeMath.sol"; import "./Strings.sol"; contract Game { using Strings for *; using SafeMath for *; address public manager; // address[] public players; struct GameInstructor { string number; uint256 totalSupply; } uint256 _totalSupply = 0; uint _GamePeriod = 1; uint _players = 0; mapping(uint => GameInstructor) GameInstructors; event log(string, uint); //变动时调用事件 function Game() public { manager = msg.sender; } function enter(uint256 _value) public onlyManagerCanCall { // require(msg.value >= .01 ether); _totalSupply = _totalSupply.add(_value); _players++; } function fetchSeed() public view returns (uint) { // uint value = uint(sha3(block.difficulty, now, _players)); log("seed number", value); return value; } function convert() view public returns (string){ uint _i = fetchSeed(); uint j = _i; uint len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (_i != 0) { bstr[k--] = byte(uint8(48 + _i % 10)); _i /= 10; } return string(bstr); } function random() public view returns (string) { string memory x = convert(); return x._substring(4, 4); } // function modifier, reduce code we need to write modifier onlyManagerCanCall() { // only manage can pick winner require(msg.sender == manager); _; // all code in your function will replace the "_" } function pickWinner() public onlyManagerCanCall { string memory GameNumber = random(); // this.balance has all the ether in current smart contract // players[index].transfer(address(this).balance); // inital dynamic array whose length is 0; // players = new address[](0); addGameInstructor(_GamePeriod, _totalSupply, GameNumber); _totalSupply = 0; _players = 0; _GamePeriod++; } function addGameInstructor(uint GamePeriodKey, uint256 periodTotal, string GameNumber) public onlyManagerCanCall { var GameInstructor = GameInstructors[GamePeriodKey]; GameInstructor.number = GameNumber; GameInstructor.totalSupply = periodTotal; } function getGame(uint GamePeriodKey) view public returns (string, uint256){ return (GameInstructors[GamePeriodKey].number, GameInstructors[GamePeriodKey].totalSupply); } function getCurrentPlayers() public view returns (uint) { return _players; } function getCurrentTotalSupply() public view returns (uint) { return _totalSupply; } }
相关推荐
PetShop-Solidity-Ethereum-Dapp
本“Introducing Ethereum Solidity”入门级文档将引导你了解以太坊网络的基础,包括其工作原理、交易机制、 Gas费用、矿工的角色等。你还将深入理解Solidity语言的关键概念,如合约的生命周期、状态变量、函数修饰...
Introducing Ethereum and Solidity-Foundations of Cryptocurrency and Blockchain Programming for Beginners. Chris Dannen. Apress
In this book we'll walk through the creation of a complete distributed application (DApp) based on the Ethereum platform. We'll be building The Neverending Story, a crowdsourced choose-your-own-...
React Ethereum Dapp示例 包括示例以太坊令牌实现和UI! 关于 这是我使用以下技术组合而成的入门样板以太坊dapp: (实现 , , , , , , , 等) 这个用于构建react / redux dapps的入门资料库使用最新的尖端...
Solidity v0.4.24 (solc-js) Node v12.0.0 web3@1.3.4 react v17.0.2 将智能合约部署到Rinkeby测试网络 合约地址0xf6e09b77560702d07472889472ab972735e699f6 使用Infura部署的合同 用于开发的松露开发套件 使用了...
“This book is dedicated to novice programmers, solution architects, and blockchain enthusiasts who want to build powerful, robust, and optimized smart contracts using solidity from scratch and in ...
workCompare distributed apps (dapps) to web appsWrite Ethereum smart contracts in SolidityConnect Ethereum smart contracts to your HTML/CSS/JavaScript web applicationsDeploy your own dapp, coin, and ...
维以太坊一个Vue.js项目构建设置 # install dependenciesnpm install# serve with hot reload at localhost:8080npm run dev# build for production with minificationnpm run build# build for production and view...
P2P借贷系统(WIP) 确保您的Ganache在7545端口上运行,或在truffle-config.js更改端口npm install npx truffle compile npx truffle test
You'll begin with a mental model of how Dapps operate, and then dive into designing and implementing smart contracts in Ethereum's Solidity language. You'll explore Ethereum smart contract ...
以太坊dapp-nuxt 这是什么? 以太坊智能合约和DApp开发框架和工作流示例,基于 + + 实现。 基于 + + 实现的版本参见: 。 开发环境 Node.js 8.x以上 Chrome 有良好控制台支持的系统 如何开发 参见掘金小册 。
Solidity是Ethereum虚拟机(EVM)上的主流智能合约编程语言,用于编写运行在区块链网络上的自执行代码。它允许开发者创建分布式、去中心化的应用程序,这些程序在不受任何单一实体控制的情况下运行。 Truffle是一个...
Solidity smart contract programming with examples; and testing, debugging, and deploying smart contracts on your local machine and on the cloud. You’ll cover best practices for writing contracts ...
4. Solidity文档与工具:文件内容中提到了多种开发工具和文档,如Solidity Documentation、Ethereum Stackexchange、Gitter等,它们是学习和开发Solidity智能合约的重要资源。文件还提到了支持Solidity开发的集成...
通过Web3.js,开发者可以构建与Ethereum网络交互的用户界面,实现DApp(去中心化应用)的功能。 在"Try-Discover-Ethereum-Solidity"项目中,我们可以看到一系列的示例和教程,帮助开发者从实践中学习这两个关键的...
ens-registrar-dapp, 注册DApp的Ethereum名称服务 Ethereum NAME 服务注册员 DApp这里应用允许你在 register 分散应用和兼容区块链浏览器中使用一个. eth 域 NAME 。检查 ens.domains 以获得有关确保。尝试应用:...