Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. pragma solidity ^0.4.17;
  2.  
  3. contract Lottery {
  4. address public manager;
  5. address[] public players;
  6.  
  7. function Lottery() public {
  8. manager = msg.sender;
  9. }
  10.  
  11. function enter() public payable {
  12. require(msg.value > .01 ether);
  13.  
  14. players.push(msg.sender);
  15. }
  16.  
  17. function random() private view returns (uint) {
  18. return uint(keccak256(block.difficulty, now, players));
  19. }
  20.  
  21. function pickWinner() public restricted {
  22. uint index = random() % players.length;
  23. players[index].transfer(this.balance);
  24. players = new address[](0);
  25. }
  26.  
  27. modifier restricted() {
  28. require(msg.sender == manager);
  29. _;
  30. }
  31.  
  32. function getPlayers() public view returns (address[]) {
  33. return players;
  34. }
  35. }
  36.  
  37. const path = require('path');
  38. const fs = require('fs');
  39. const solc = require('solc');
  40.  
  41. const lotteryPath = path.resolve(__dirname, 'contracts', 'Lottery.sol');
  42. const source = fs.readFileSync(lotteryPath, 'utf8');
  43.  
  44. module.exports = solc.compile(source, 1).contracts[':Lottery'];
  45. const path = require('path');
  46. const fs = require('fs');
  47. const solc = require('solc');
  48.  
  49. const lotteryPath = path.resolve(__dirname, 'contracts', 'Lottery.sol');
  50. const source = fs.readFileSync(lotteryPath, 'utf8');
  51.  
  52. module.exports = solc.compile(source, 1).contracts[':Lottery'];
  53.  
  54. const HDWalletProvider = require('truffle-hdwallet-provider');
  55. const Web3 = require('web3');
  56. const { interface, bytecode } = require('./compile');
  57.  
  58. const provider = new HDWalletProvider(
  59. 'joy nuclear cause beauty strike quick priority upset hello strategy manual shadow',
  60. 'rinkeby.infura.io/v3/979787f2e36741368aee9a3d1b73b438'
  61. );
  62. const web3 = new Web3(provider);
  63.  
  64. const deploy = async () => {
  65. const accounts = await web3.eth.getAccounts();
  66.  
  67. console.log('Attempting to deploy from account', accounts[0]);
  68.  
  69. const result = await new web3.eth.Contract(JSON.parse(interface))
  70. .deploy({ data: bytecode })
  71. .send({ gas: '1000000', from: accounts[0] });
  72.  
  73. console.log('Contract deployed to', result.options.address);
  74. };
  75. deploy();
  76.  
  77. {
  78. "name": "set",
  79. "version": "1.0.0",
  80. "description": "",
  81. "main": "index.js",
  82. "scripts": {
  83. "test": "mocha"
  84. },
  85. "author": "",
  86. "license": "ISC",
  87. "dependencies": {
  88. "ganache-cli": "^6.4.3",
  89. "mocha": "^6.1.4",
  90. "solc": "^0.4.17",
  91. "truffle-hdwallet-provider": "^1.0.9",
  92. "web3": "^1.0.0-beta.37"
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement