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; } }
相关推荐
Introducing Ethereum Solidity 以太坊 pdf 入门级文档
PetShop-Solidity-Ethereum-Dapp
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 有良好控制台支持的系统 如何开发 参见掘金小册 。
2021 深度了解以太坊編程語言
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 ...
ens-registrar-dapp, 注册DApp的Ethereum名称服务 Ethereum NAME 服务注册员 DApp这里应用允许你在 register 分散应用和兼容区块链浏览器中使用一个. eth 域 NAME 。检查 ens.domains 以获得有关确保。尝试应用:...
Try-Discover-Ethereum-Solidity
以太坊带有Solidity Smart Contract后端的Node,Express,GraphQL服务器!在你开始之前安装MetaMask以太坊钱包(并注册一个帐户): ://metamask.io/ 安装: npm i -g ganache-cli (本地以太坊测试网络)运行项目...
利用这个投票应用,用户可以在不可信(trustless)的分布环境中对特定候选人投票,每次投票都会被记录在区块链上:所谓去中心化应用(DApp:DcentralizedApplication),就是一个不存在中心服务器的应用。...