├── .gitignore ├── tutorial-21 ├── .gitignore ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── truffle.js ├── contracts │ ├── ConvertLib.sol │ ├── Migrations.sol │ └── MetaCoin.sol ├── README.MD └── test │ ├── TestMetacoin.sol │ └── metacoin.js ├── tutorial-22 ├── .gitignore ├── truffle.js ├── truffle-config.js ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── contracts │ ├── ERC223ReceivingContract.sol │ ├── ERC223.sol │ ├── Addresses.sol │ ├── ERC20.sol │ ├── Migrations.sol │ ├── SafeMath.sol │ ├── Token.sol │ ├── Crowdsale.sol │ └── MyToken.sol ├── README.MD └── test │ ├── TestMyToken.sol │ ├── TestMyToken.js │ └── TestCrowdsale.js ├── _config.yml ├── .gitattributes ├── tutorial-31 ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── build.gradle ├── README.MD ├── src │ └── main │ │ ├── resources │ │ ├── out │ │ │ ├── AddressBook.abi │ │ │ └── AddressBook.bin │ │ └── solidity │ │ │ └── AddressBook.sol │ │ └── java │ │ └── youtube │ │ └── solidity │ │ └── learning │ │ ├── Main.java │ │ └── contracts │ │ └── AddressBook.java ├── gradlew.bat └── gradlew ├── tutorial-32 ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── build.gradle ├── README.MD ├── src │ └── main │ │ ├── resources │ │ ├── out │ │ │ ├── AddressBook.abi │ │ │ └── AddressBook.bin │ │ └── solidity │ │ │ └── AddressBook.sol │ │ └── java │ │ └── youtube │ │ └── solidity │ │ └── learning │ │ ├── Main.java │ │ └── contracts │ │ └── AddressBook.java ├── gradlew.bat └── gradlew ├── tutorial-33 ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── build.gradle ├── README.MD ├── src │ └── main │ │ ├── resources │ │ ├── out │ │ │ ├── AddressBook.abi │ │ │ └── AddressBook.bin │ │ └── solidity │ │ │ └── AddressBook.sol │ │ └── java │ │ └── youtube │ │ └── solidity │ │ └── learning │ │ ├── Main.java │ │ └── contracts │ │ └── AddressBook.java ├── gradlew.bat └── gradlew ├── tutorial-27 ├── styles │ └── styles.css ├── package.json ├── README.MD ├── Gruntfile.js ├── scripts │ └── metamask.js └── index.html ├── tutorial-28 ├── public │ ├── src │ │ ├── styles │ │ │ └── styles.css │ │ ├── templates │ │ │ ├── home.html │ │ │ ├── address.html │ │ │ └── addresses.html │ │ ├── scripts │ │ │ ├── factories │ │ │ │ ├── factories.js │ │ │ │ └── ethereum.js │ │ │ ├── controllers │ │ │ │ ├── controllers.js │ │ │ │ └── addresses.js │ │ │ ├── app.js │ │ │ └── contracts │ │ │ │ └── addressbook.json │ │ └── index.html │ ├── package.json │ └── Gruntfile.js ├── solidity │ ├── truffle-config.js │ ├── migrations │ │ ├── 2_deploy_contracts.js │ │ └── 1_initial_migration.js │ ├── truffle.js │ └── contracts │ │ ├── Migrations.sol │ │ └── AddressBook.sol └── README.MD ├── support └── images │ ├── nested_array_memory_layout.png │ └── nested_array_storage_layout.png ├── tutorial-25 ├── truffle.js ├── truffle-config.js ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── README.MD └── contracts │ ├── Migrations.sol │ └── MultiSigWallet.sol ├── tutorial-26 ├── truffle.js ├── truffle-config.js ├── migrations │ ├── 1_initial_migration.js │ └── 2_deploy_contracts.js ├── README.MD ├── contracts │ ├── Migrations.sol │ └── MultiSigWallet.sol └── test │ └── TestMultiSigWallet.js ├── tutorial-10 ├── ERC223ReceivingContract.sol ├── ERC223.sol ├── ERC20.sol ├── Token.sol └── MyFirstToken.sol ├── tutorial-11 ├── ERC223ReceivingContract.sol ├── ERC223.sol ├── ERC20.sol ├── Token.sol ├── MyFirstToken.sol └── Compiled.sol ├── tutorial-15 └── ExternalContract.sol ├── tutorial-07 ├── TestStrings.sol └── Strings.sol ├── tutorial-18 ├── Random.sol └── Casino.sol ├── tutorial-01 └── myfirstcontract.sol ├── tutorial-04 ├── library.sol └── testLibrary.sol ├── tutorial-08 └── Debugging.sol ├── tutorial-29 └── Denominations.sol ├── tutorial-05 └── transaction.sol ├── tutorial-23 └── StateModifiers.sol ├── tutorial-20 └── Assignments.sol ├── tutorial-30 └── Gas.sol ├── tutorial-09 ├── ERC20.sol └── MyToken.sol ├── tutorial-14 └── EtherTransfer.sol ├── tutorial-13 └── Assembly.sol ├── tutorial-12 └── Assembly.sol ├── tutorial-16 ├── AlarmTrigger.sol └── TimeBased.sol ├── tutorial-17 └── Alphabet.sol ├── tutorial-06 └── DataTypes.sol ├── tutorial-02 └── myfirstcontract.sol ├── tutorial-24 └── MultiSigWallet.sol ├── tutorial-03 └── myfirstcontract.sol ├── tutorial-19 └── NestedArrays.sol └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea -------------------------------------------------------------------------------- /tutorial-21/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /tutorial-22/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /tutorial-31/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'tutorial-31' 2 | -------------------------------------------------------------------------------- /tutorial-32/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'tutorial-32' 2 | -------------------------------------------------------------------------------- /tutorial-33/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'tutorial-33' 2 | -------------------------------------------------------------------------------- /tutorial-27/styles/styles.css: -------------------------------------------------------------------------------- 1 | .spacer { 2 | margin-top: 5em; 3 | } 4 | -------------------------------------------------------------------------------- /tutorial-28/public/src/styles/styles.css: -------------------------------------------------------------------------------- 1 | .spacer { 2 | margin-top: 5em; 3 | } 4 | -------------------------------------------------------------------------------- /tutorial-28/public/src/templates/home.html: -------------------------------------------------------------------------------- 1 |

Welcome to the Solidity address book demo

2 | -------------------------------------------------------------------------------- /tutorial-28/public/src/templates/address.html: -------------------------------------------------------------------------------- 1 |

This is the partial for view 2.

2 |

Address

3 | -------------------------------------------------------------------------------- /support/images/nested_array_memory_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willitscale/learning-solidity/HEAD/support/images/nested_array_memory_layout.png -------------------------------------------------------------------------------- /support/images/nested_array_storage_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willitscale/learning-solidity/HEAD/support/images/nested_array_storage_layout.png -------------------------------------------------------------------------------- /tutorial-31/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willitscale/learning-solidity/HEAD/tutorial-31/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tutorial-32/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willitscale/learning-solidity/HEAD/tutorial-32/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tutorial-33/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willitscale/learning-solidity/HEAD/tutorial-33/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tutorial-22/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-25/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-26/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-22/truffle-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-25/truffle-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-26/truffle-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-28/public/src/scripts/factories/factories.js: -------------------------------------------------------------------------------- 1 | require('./ethereum'); 2 | 3 | angular.module('learningSolidity.factories', [ 4 | 'learningSolidity.factories.ethereum' 5 | ]); 6 | -------------------------------------------------------------------------------- /tutorial-28/solidity/truffle-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tutorial-10/ERC223ReceivingContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract ERC223ReceivingContract { 4 | function tokenFallback(address _from, uint _value, bytes _data) public; 5 | } -------------------------------------------------------------------------------- /tutorial-11/ERC223ReceivingContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract ERC223ReceivingContract { 4 | function tokenFallback(address _from, uint _value, bytes _data) public; 5 | } -------------------------------------------------------------------------------- /tutorial-21/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-22/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-25/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-26/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-28/public/src/scripts/controllers/controllers.js: -------------------------------------------------------------------------------- 1 | require('./addresses'); 2 | 3 | angular.module('learningSolidity.controllers', [ 4 | 'learningSolidity.controllers.addresses' 5 | ]); 6 | -------------------------------------------------------------------------------- /tutorial-28/solidity/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var AddressBook = artifacts.require("./AddressBook.sol"); 2 | 3 | module.exports = deployer => { 4 | deployer.deploy(AddressBook); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-26/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var MultiSigWallet = artifacts.require("./MultiSigWallet.sol"); 2 | 3 | module.exports = deployer => { 4 | deployer.deploy(MultiSigWallet); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-28/solidity/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-22/contracts/ERC223ReceivingContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract ERC223ReceivingContract { 4 | function tokenFallback(address _from, uint _value, bytes _data) public; 5 | } 6 | -------------------------------------------------------------------------------- /tutorial-25/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var MultiSigWallet = artifacts.require("./MultiSigWallet.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(MultiSigWallet); 5 | }; 6 | -------------------------------------------------------------------------------- /tutorial-21/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: "localhost", 5 | port: 8545, 6 | network_id: "*" // Match any network id 7 | } 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /tutorial-28/solidity/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | host: "127.0.0.1", 5 | port: 8545, 6 | network_id: "*", 7 | gas: 4600000 8 | } 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /tutorial-21/contracts/ConvertLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | library ConvertLib{ 4 | function convert(uint amount,uint conversionRate) returns (uint convertedAmount) 5 | { 6 | return amount * conversionRate; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tutorial-11/ERC223.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC223 { 4 | function transfer(address _to, uint _value, bytes _data) public returns (bool); 5 | event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); 6 | } -------------------------------------------------------------------------------- /tutorial-10/ERC223.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC223 { 4 | function transfer(address _to, uint _value, bytes _data) public returns (bool); 5 | event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); 6 | } 7 | -------------------------------------------------------------------------------- /tutorial-22/contracts/ERC223.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC223 { 4 | function transfer(address _to, uint _value, bytes _data) public returns (bool); 5 | event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); 6 | } 7 | -------------------------------------------------------------------------------- /tutorial-27/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learning-solidity", 3 | "version": "1.0.0", 4 | "devDependencies": { 5 | "grunt": "^0.4.5", 6 | "grunt-contrib-connect": "^1.0.2", 7 | "grunt-contrib-jshint": "^0.10.0", 8 | "grunt-contrib-watch": "^1.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tutorial-31/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 26 01:59:24 BST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip 7 | -------------------------------------------------------------------------------- /tutorial-32/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 26 01:59:24 BST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip 7 | -------------------------------------------------------------------------------- /tutorial-33/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 26 01:59:24 BST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip 7 | -------------------------------------------------------------------------------- /tutorial-21/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var ConvertLib = artifacts.require("./ConvertLib.sol"); 2 | var MetaCoin = artifacts.require("./MetaCoin.sol"); 3 | 4 | module.exports = function(deployer) { 5 | deployer.deploy(ConvertLib); 6 | deployer.link(ConvertLib, MetaCoin); 7 | deployer.deploy(MetaCoin); 8 | }; 9 | -------------------------------------------------------------------------------- /tutorial-31/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'idea' 3 | 4 | sourceCompatibility = 1.8 5 | targetCompatibility = 1.8 6 | 7 | repositories { 8 | mavenCentral() 9 | jcenter() 10 | } 11 | 12 | dependencies { 13 | compile ('org.web3j:core:3.5.0') 14 | testCompile("junit:junit") 15 | } 16 | -------------------------------------------------------------------------------- /tutorial-32/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'idea' 3 | 4 | sourceCompatibility = 1.8 5 | targetCompatibility = 1.8 6 | 7 | repositories { 8 | mavenCentral() 9 | jcenter() 10 | } 11 | 12 | dependencies { 13 | compile ('org.web3j:core:3.5.0') 14 | testCompile("junit:junit") 15 | } 16 | -------------------------------------------------------------------------------- /tutorial-33/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'idea' 3 | 4 | sourceCompatibility = 1.8 5 | targetCompatibility = 1.8 6 | 7 | repositories { 8 | mavenCentral() 9 | jcenter() 10 | } 11 | 12 | dependencies { 13 | compile ('org.web3j:core:3.5.0') 14 | testCompile("junit:junit") 15 | } 16 | -------------------------------------------------------------------------------- /tutorial-22/contracts/Addresses.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | library Addresses { 4 | function isContract(address _base) internal constant returns (bool) { 5 | uint codeSize; 6 | assembly { 7 | codeSize := extcodesize(_base) 8 | } 9 | return codeSize > 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tutorial-15/ExternalContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract ExternalContract { 4 | function externalCall(string calldata x) external returns (uint) { 5 | return 123; 6 | } 7 | 8 | function publicCall(string memory x) public returns (uint) { 9 | return 123; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tutorial-27/README.MD: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | Download: 4 | - [NPM](https://www.npmjs.com/get-npm) 5 | - [Atom](https://atom.io/) 6 | - [Metamask](https://metamask.io/) 7 | 8 | 9 | Running testrpc with Metamask seed: 10 | ``` 11 | testrpc -m "SEED_HERE" 12 | ``` 13 | 14 | Building the project: 15 | ``` 16 | npm install 17 | ``` 18 | 19 | Running grunt connect: 20 | ``` 21 | grunt 22 | ``` 23 | -------------------------------------------------------------------------------- /tutorial-11/ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC20 { 4 | function transferFrom(address _from, address _to, uint _value) public returns (bool); 5 | function approve(address _spender, uint _value) public returns (bool); 6 | function allowance(address _owner, address _spender) public constant returns (uint); 7 | event Approval(address indexed _owner, address indexed _spender, uint _value); 8 | } -------------------------------------------------------------------------------- /tutorial-10/ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC20 { 4 | function transferFrom(address _from, address _to, uint _value) external returns (bool); 5 | function approve(address _spender, uint _value) external returns (bool); 6 | function allowance(address _owner, address _spender) external constant returns (uint); 7 | event Approval(address indexed _owner, address indexed _spender, uint _value); 8 | } 9 | -------------------------------------------------------------------------------- /tutorial-22/contracts/ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC20 { 4 | function transferFrom(address _from, address _to, uint _value) public returns (bool); 5 | function approve(address _spender, uint _value) public returns (bool); 6 | function allowance(address _owner, address _spender) public view returns (uint); 7 | event Approval(address indexed _owner, address indexed _spender, uint _value); 8 | } 9 | -------------------------------------------------------------------------------- /tutorial-07/TestStrings.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "browser/Strings.sol"; 4 | 5 | contract TestStrings { 6 | 7 | using Strings for string; 8 | 9 | function testConcat(string _base) public pure returns (string) { 10 | return _base.concat("_suffix"); 11 | } 12 | 13 | function needleInHaystack(string _base) public pure returns (int) { 14 | return _base.strpos("t"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tutorial-18/Random.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Random { 4 | 5 | function unsafeBlockRandom() 6 | public 7 | returns (uint) { 8 | return uint(block.blockhash(block.number-1)) % 100; 9 | } 10 | 11 | uint private _baseIncrement; 12 | 13 | function unsafeIncrementRandom() 14 | public 15 | returns (uint) { 16 | return uint(sha3(_baseIncrement++)) % 100; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /tutorial-21/README.MD: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | Download: 4 | - [NPM](https://www.npmjs.com/get-npm) 5 | - [Atom](https://atom.io/) 6 | 7 | Run the following commands: 8 | ``` 9 | npm install -g truffle 10 | npm install -g ethereumjs-testrpc 11 | ``` 12 | 13 | To compile the project run: 14 | ``` 15 | truffle compile 16 | ``` 17 | 18 | To migrate the project run: 19 | ``` 20 | truffle migrate 21 | ``` 22 | 23 | To test the project run: 24 | ``` 25 | truffle test 26 | ``` -------------------------------------------------------------------------------- /tutorial-22/README.MD: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | Download: 4 | - [NPM](https://www.npmjs.com/get-npm) 5 | - [Atom](https://atom.io/) 6 | 7 | Run the following commands: 8 | ``` 9 | npm install -g truffle 10 | npm install -g ethereumjs-testrpc 11 | ``` 12 | 13 | To compile the project run: 14 | ``` 15 | truffle compile 16 | ``` 17 | 18 | To migrate the project run: 19 | ``` 20 | truffle migrate 21 | ``` 22 | 23 | To test the project run: 24 | ``` 25 | truffle test 26 | ``` -------------------------------------------------------------------------------- /tutorial-25/README.MD: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | Download: 4 | - [NPM](https://www.npmjs.com/get-npm) 5 | - [Atom](https://atom.io/) 6 | 7 | Run the following commands: 8 | ``` 9 | npm install -g truffle 10 | npm install -g ethereumjs-testrpc 11 | ``` 12 | 13 | To compile the project run: 14 | ``` 15 | truffle compile 16 | ``` 17 | 18 | To migrate the project run: 19 | ``` 20 | truffle migrate 21 | ``` 22 | 23 | To test the project run: 24 | ``` 25 | truffle test 26 | ``` -------------------------------------------------------------------------------- /tutorial-26/README.MD: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | Download: 4 | - [NPM](https://www.npmjs.com/get-npm) 5 | - [Atom](https://atom.io/) 6 | 7 | Run the following commands: 8 | ``` 9 | npm install -g truffle 10 | npm install -g ethereumjs-testrpc 11 | ``` 12 | 13 | To compile the project run: 14 | ``` 15 | truffle compile 16 | ``` 17 | 18 | To migrate the project run: 19 | ``` 20 | truffle migrate 21 | ``` 22 | 23 | To test the project run: 24 | ``` 25 | truffle test 26 | ``` -------------------------------------------------------------------------------- /tutorial-28/public/src/scripts/factories/ethereum.js: -------------------------------------------------------------------------------- 1 | angular.module('learningSolidity.factories.ethereum', []) 2 | .factory("EthereumContract", function () { 3 | const Eth = require('ethjs-query'); 4 | const EthContract = require('ethjs-contract'); 5 | return { 6 | contract: function(abi, address) { 7 | const eth = new Eth(web3.currentProvider); 8 | const contract = new EthContract(eth); 9 | return contract(abi).at(address); 10 | } 11 | }; 12 | }); 13 | -------------------------------------------------------------------------------- /tutorial-28/public/src/scripts/app.js: -------------------------------------------------------------------------------- 1 | require('angular/angular'); 2 | require('angular-route/angular-route'); 3 | 4 | require('./controllers/controllers'); 5 | require('./factories/factories'); 6 | 7 | angular.module('learningSolidity', [ 8 | 'ngRoute', 9 | 'learningSolidity.controllers', 10 | 'learningSolidity.factories' 11 | ]) 12 | .config(['$routeProvider', function($routeProvider) { 13 | $routeProvider 14 | .when('/', { 15 | templateUrl: 'templates/home.html' 16 | }); 17 | }]); 18 | -------------------------------------------------------------------------------- /tutorial-01/myfirstcontract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract MyFirstContract { 4 | string private name; 5 | uint private age; 6 | 7 | function setName(string memory newName) public { 8 | name = newName; 9 | } 10 | 11 | function getName() public view returns (string memory) { 12 | return name; 13 | } 14 | 15 | function setAge(uint newAge) public { 16 | age = newAge; 17 | } 18 | 19 | function getAge() public view returns (uint) { 20 | return age; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tutorial-04/library.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | library IntExtended { 4 | 5 | function increment(uint _self) public pure returns (uint) { 6 | return _self+1; 7 | } 8 | 9 | function decrement(uint _self) public pure returns (uint) { 10 | return _self-1; 11 | } 12 | 13 | function incrementByValue(uint _self, uint _value) public pure returns (uint) { 14 | return _self + _value; 15 | } 16 | 17 | function decrementByValue(uint _self, uint _value) public pure returns (uint) { 18 | return _self - _value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tutorial-08/Debugging.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Debugging { 4 | 5 | uint[] private vars; 6 | 7 | function assignment() public pure { 8 | uint myVal1 = 1; 9 | uint myVal2 = 2; 10 | assert(myVal1 == myVal2); 11 | } 12 | 13 | function memoryAlloc() public pure { 14 | string memory myString = "test"; 15 | assert(bytes(myString).length == 10); 16 | } 17 | 18 | function storageAlloc() public { 19 | vars.push(2); 20 | vars.push(3); 21 | assert(vars.length == 4); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tutorial-21/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tutorial-29/Denominations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Denominations { 4 | // WEI Denominations 5 | uint constant WEI = 1 wei; 6 | uint constant KWEI = 1000 wei; 7 | uint constant MWEI = 1000000 wei; 8 | uint constant GWEI = 1000000000 wei; 9 | 10 | // Ether Denominations 11 | uint constant MICROETHER = 1 szabo; 12 | uint constant MILLIETHER = 1 finney; 13 | uint constant ETHER = 1 ether; 14 | uint constant KETHER = 1000 ether; 15 | uint constant METHER = 1000000 ether; 16 | uint constant GETHER = 1000000000 ether; 17 | uint constant TETHER = 1000000000000 ether; 18 | } 19 | -------------------------------------------------------------------------------- /tutorial-22/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.17; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tutorial-25/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.17; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tutorial-26/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.17; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tutorial-28/public/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "learning-solidity", 3 | "version": "1.0.0", 4 | "devDependencies": { 5 | "ethjs-contract": "^0.1.9", 6 | "ethjs-query": "^0.3.2", 7 | "grunt": "^0.4.5", 8 | "grunt-browserify": "^5.2.0", 9 | "grunt-contrib-connect": "^1.0.2", 10 | "grunt-contrib-copy": "^1.0.0", 11 | "grunt-contrib-jshint": "^0.12.0", 12 | "grunt-contrib-watch": "^1.0.0", 13 | "napa": "^3.0.0" 14 | }, 15 | "scripts": { 16 | "install": "napa" 17 | }, 18 | "napa": { 19 | "angular": "angular/bower-angular", 20 | "angular-route": "angular/bower-angular-route" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tutorial-28/solidity/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.17; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | function Migrations() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tutorial-05/transaction.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Transaction { 4 | 5 | event SenderLogger(address); 6 | event ValueLogger(uint); 7 | 8 | address private owner; 9 | 10 | modifier isOwner { 11 | require(owner == msg.sender); 12 | _; 13 | } 14 | 15 | modifier validValue { 16 | assert(msg.value >= 1 ether); 17 | _; 18 | } 19 | 20 | constructor() public { 21 | owner = msg.sender; 22 | } 23 | 24 | function () public payable isOwner validValue { 25 | emit SenderLogger(msg.sender); 26 | emit ValueLogger(msg.value); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tutorial-23/StateModifiers.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract StateModifiers { 4 | uint private constant varConstantValue = 55; 5 | uint private stateValue; 6 | 7 | function stateAccess() public returns (uint) { 8 | stateValue = 10; 9 | return stateValue; 10 | } 11 | 12 | function constantAccess() public constant returns (uint) { 13 | return block.number; 14 | } 15 | 16 | function viewAccess() public view returns (uint) { 17 | return stateValue; 18 | } 19 | 20 | function pureAccess() public pure returns (uint) { 21 | return varConstantValue; 22 | } 23 | } -------------------------------------------------------------------------------- /tutorial-31/README.MD: -------------------------------------------------------------------------------- 1 | # Learning Solidity Tutorial 31 2 | 3 | What you'll need: 4 | - Download the web3j command line client from [here](https://github.com/web3j/web3j/releases/tag/v3.6.0) 5 | - Download the solc binaries from [here](https://github.com/ethereum/solidity/releases) 6 | 7 | Web3j Documentation : https://docs.web3j.io/ 8 | 9 | Building the solidity: 10 | 11 | ``` 12 | solc src/main/resources/solidity/AddressBook.sol --bin --abi --optimize -o src/main/resources/out 13 | ``` 14 | 15 | Building the Java: 16 | ``` 17 | web3j solidity generate src/main/resources/out/AddressBook.bin src/main/resources/out/AddressBook.abi -o src/main/java -p youtube.solidity.learning.contracts 18 | ``` -------------------------------------------------------------------------------- /tutorial-32/README.MD: -------------------------------------------------------------------------------- 1 | # Learning Solidity Tutorial 32 2 | 3 | What you'll need: 4 | - Download the web3j command line client from [here](https://github.com/web3j/web3j/releases/tag/v3.6.0) 5 | - Download the solc binaries from [here](https://github.com/ethereum/solidity/releases) 6 | 7 | Web3j Documentation : https://docs.web3j.io/ 8 | 9 | Building the solidity: 10 | 11 | ``` 12 | solc src/main/resources/solidity/AddressBook.sol --bin --abi --optimize -o src/main/resources/out 13 | ``` 14 | 15 | Building the Java: 16 | ``` 17 | web3j solidity generate src/main/resources/out/AddressBook.bin src/main/resources/out/AddressBook.abi -o src/main/java -p youtube.solidity.learning.contracts 18 | ``` 19 | -------------------------------------------------------------------------------- /tutorial-33/README.MD: -------------------------------------------------------------------------------- 1 | # Learning Solidity Tutorial 33 2 | 3 | What you'll need: 4 | - Download the web3j command line client from [here](https://github.com/web3j/web3j/releases/tag/v3.6.0) 5 | - Download the solc binaries from [here](https://github.com/ethereum/solidity/releases) 6 | 7 | Web3j Documentation : https://docs.web3j.io/ 8 | 9 | Building the solidity: 10 | 11 | ``` 12 | solc src/main/resources/solidity/AddressBook.sol --bin --abi --optimize -o src/main/resources/out 13 | ``` 14 | 15 | Building the Java: 16 | ``` 17 | web3j solidity generate src/main/resources/out/AddressBook.bin src/main/resources/out/AddressBook.abi -o src/main/java -p youtube.solidity.learning.contracts 18 | ``` 19 | -------------------------------------------------------------------------------- /tutorial-31/src/main/resources/out/AddressBook.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"removeAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getAlias","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAddresses","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"alias","type":"string"}],"name":"addAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /tutorial-32/src/main/resources/out/AddressBook.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"removeAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getAlias","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAddresses","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"alias","type":"string"}],"name":"addAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /tutorial-33/src/main/resources/out/AddressBook.abi: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"removeAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"addr","type":"address"}],"name":"getAlias","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAddresses","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"alias","type":"string"}],"name":"addAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /tutorial-20/Assignments.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Assignments { 4 | function returnFirstValue(uint a, uint b) returns (uint) { 5 | return a; 6 | } 7 | 8 | function caller() public returns (uint) { 9 | return returnFirstValue({b:4, a:8}); 10 | } 11 | 12 | function returnAllValues(uint a, uint b, uint c) returns (uint, uint, uint) { 13 | return (a,b,c); 14 | } 15 | 16 | function callerAll() public returns (uint, uint, uint) { 17 | var(x,y,z) = returnAllValues(4,5,6); 18 | (x,y) = (y,x); 19 | (x,) = returnAllValues(5,10,15); 20 | (,z) = returnAllValues(10,20,30); 21 | return (x,y,z); 22 | } 23 | } -------------------------------------------------------------------------------- /tutorial-27/Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | grunt.initConfig({ 4 | pkg: grunt.file.readJSON('package.json'), 5 | watch: { 6 | scripts: { 7 | files: ['scripts/*.js'], 8 | tasks: ['jshint'], 9 | options: { 10 | spawn: false, 11 | }, 12 | } 13 | }, 14 | connect: { 15 | server: { 16 | options: { 17 | port: 8000, 18 | hostname: '*', 19 | base: './' 20 | } 21 | } 22 | } 23 | }); 24 | 25 | grunt.loadNpmTasks('grunt-contrib-watch'); 26 | grunt.loadNpmTasks('grunt-contrib-connect'); 27 | 28 | grunt.registerTask('default', ['connect','watch']); 29 | }; 30 | -------------------------------------------------------------------------------- /tutorial-22/migrations/2_deploy_contracts.js: -------------------------------------------------------------------------------- 1 | var SafeMath = artifacts.require("./SafeMath.sol"); 2 | var MyToken = artifacts.require("./MyToken.sol"); 3 | var Addresses = artifacts.require("./Addresses.sol"); 4 | var Crowdsale = artifacts.require("./Crowdsale.sol"); 5 | 6 | module.exports = function(deployer) { 7 | deployer.deploy(SafeMath); 8 | deployer.link(SafeMath, MyToken); 9 | deployer.deploy(Addresses); 10 | deployer.link(Addresses, MyToken); 11 | deployer.deploy(MyToken).then(function(){ 12 | return deployer.deploy( 13 | Crowdsale, 14 | MyToken.address, 15 | web3.eth.blockNumber, 16 | web3.eth.blockNumber+1000, 17 | web3.toWei(1, 'ether'), 18 | 1 19 | ).then(function(){}); 20 | }); 21 | }; 22 | -------------------------------------------------------------------------------- /tutorial-30/Gas.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Gas { 4 | 5 | string[] dataStore; 6 | 7 | function cheap(uint a, uint b) 8 | public 9 | pure 10 | returns (uint c) 11 | { 12 | c = a + b; 13 | } 14 | 15 | function expensive(string memory val) 16 | public 17 | { 18 | dataStore.push(val); 19 | } 20 | 21 | function average() 22 | public 23 | view 24 | returns (string memory) 25 | { 26 | return dataStore[0]; 27 | } 28 | 29 | function low() 30 | public 31 | pure 32 | returns (string memory) 33 | { 34 | string memory myString = "test"; 35 | return myString; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tutorial-04/testLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "browser/library.sol"; 4 | 5 | contract TestLibrary { 6 | using IntExtended for uint; 7 | 8 | function testIncrement(uint _base) public pure returns (uint) { 9 | return IntExtended.increment(_base); 10 | } 11 | 12 | function testDecrement(uint _base) public pure returns (uint) { 13 | return IntExtended.decrement(_base); 14 | } 15 | 16 | function testIncrementByValue(uint _base, uint _value) public pure returns (uint) { 17 | return _base.incrementByValue(_value); 18 | } 19 | 20 | function testDecrementByValue(uint _base, uint _value) public pure returns (uint) { 21 | return _base.decrementByValue(_value); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tutorial-09/ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC20 { 4 | function totalSupply() external constant returns (uint _totalSupply); 5 | function balanceOf(address _owner) external constant returns (uint balance); 6 | function transfer(address _to, uint _value) external returns (bool success); 7 | function transferFrom(address _from, address _to, uint _value) external returns (bool success); 8 | function approve(address _spender, uint _value) external returns (bool success); 9 | function allowance(address _owner, address _spender) external constant returns (uint remaining); 10 | event Transfer(address indexed _from, address indexed _to, uint _value); 11 | event Approval(address indexed _owner, address indexed _spender, uint _value); 12 | } 13 | -------------------------------------------------------------------------------- /tutorial-31/src/main/java/youtube/solidity/learning/Main.java: -------------------------------------------------------------------------------- 1 | package youtube.solidity.learning; 2 | 3 | import org.web3j.protocol.Web3j; 4 | import org.web3j.protocol.core.methods.response.Web3ClientVersion; 5 | import org.web3j.protocol.http.HttpService; 6 | 7 | import java.io.IOException; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | Web3j web3j = Web3j.build(new HttpService()); 12 | Web3ClientVersion web3ClientVersion = null; 13 | try { 14 | web3ClientVersion = web3j.web3ClientVersion().send(); 15 | } catch (IOException e) { 16 | e.printStackTrace(); 17 | } 18 | String web3ClientVersionString = web3ClientVersion.getWeb3ClientVersion(); 19 | System.out.println("Web3 client version: " + web3ClientVersionString); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tutorial-22/contracts/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | library SafeMath { 4 | function sub(uint _base, uint _value) 5 | internal 6 | pure 7 | returns (uint) { 8 | assert(_value <= _base); 9 | return _base - _value; 10 | } 11 | 12 | function add(uint _base, uint _value) 13 | internal 14 | pure 15 | returns (uint _ret) { 16 | _ret = _base + _value; 17 | assert(_ret >= _base); 18 | } 19 | 20 | function div(uint _base, uint _value) 21 | internal 22 | pure 23 | returns (uint) { 24 | assert(_value > 0 && (_base % _value) == 0); 25 | return _base / _value; 26 | } 27 | 28 | function mul(uint _base, uint _value) 29 | internal 30 | pure 31 | returns (uint _ret) { 32 | _ret = _base * _value; 33 | assert(0 == _base || _ret / _base == _value); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tutorial-21/test/TestMetacoin.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.2; 2 | 3 | import "truffle/Assert.sol"; 4 | import "truffle/DeployedAddresses.sol"; 5 | import "../contracts/MetaCoin.sol"; 6 | 7 | contract TestMetacoin { 8 | 9 | MetaCoin meta; 10 | 11 | function testInitialBalanceUsingDeployedContract() { 12 | meta = MetaCoin(DeployedAddresses.MetaCoin()); 13 | 14 | uint expected = 10000; 15 | 16 | Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); 17 | } 18 | 19 | function testInitialBalanceWithNewMetaCoin() { 20 | 21 | uint expected = 10000; 22 | 23 | Assert.equal(meta.getBalance(tx.origin), expected, "Owner should have 10000 MetaCoin initially"); 24 | } 25 | 26 | function testFailureCondition() { 27 | Assert.equal(meta.getBalance(tx.origin), 0, "This should fail"); 28 | } 29 | 30 | function beforeAll() { 31 | meta = new MetaCoin(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tutorial-14/EtherTransfer.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract EtherTransferTo { 4 | function () external payable { 5 | } 6 | 7 | function getBalance() public returns (uint) { 8 | return address(this).balance; 9 | } 10 | } 11 | 12 | contract EtherTransferFrom { 13 | 14 | EtherTransferTo private _instance; 15 | 16 | constructor() public { 17 | // _instance = EtherTransferTo(address(this)); 18 | _instance = new EtherTransferTo(); 19 | } 20 | 21 | function getBalance() public returns (uint) { 22 | return address(this).balance; 23 | } 24 | 25 | function getBalanceOfInstance() public returns (uint) { 26 | //return address(_instance).balance; 27 | return _instance.getBalance(); 28 | } 29 | 30 | function () external payable { 31 | //msg.sender.send(msg.value); 32 | address(_instance).send(msg.value); 33 | } 34 | } -------------------------------------------------------------------------------- /tutorial-21/contracts/MetaCoin.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | import "./ConvertLib.sol"; 4 | 5 | // This is just a simple example of a coin-like contract. 6 | // It is not standards compatible and cannot be expected to talk to other 7 | // coin/token contracts. If you want to create a standards-compliant 8 | // token, see: https://github.com/ConsenSys/Tokens. Cheers! 9 | 10 | contract MetaCoin { 11 | mapping (address => uint) balances; 12 | 13 | event Transfer(address indexed _from, address indexed _to, uint256 _value); 14 | 15 | function MetaCoin() { 16 | balances[tx.origin] = 10000; 17 | } 18 | 19 | function sendCoin(address receiver, uint amount) returns(bool sufficient) { 20 | if (balances[msg.sender] < amount) return false; 21 | balances[msg.sender] -= amount; 22 | balances[receiver] += amount; 23 | Transfer(msg.sender, receiver, amount); 24 | return true; 25 | } 26 | 27 | function getBalanceInEth(address addr) returns(uint){ 28 | return ConvertLib.convert(getBalance(addr),2); 29 | } 30 | 31 | function getBalance(address addr) returns(uint) { 32 | return balances[addr]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tutorial-27/scripts/metamask.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | if (typeof(window.web3) != 'undefined') { 3 | $('#no-meta-mask').hide(); 4 | getBalances(web3.currentProvider); 5 | } else { 6 | $('#has-metamask').hide(); 7 | } 8 | }); 9 | 10 | function getBalances(provider) { 11 | var ethWeb3 = new Web3(provider); 12 | ethWeb3.eth.getAccounts(function (err, accounts) { 13 | for(var i = 0; i < accounts.length; i++) { 14 | var account = accounts[i]; 15 | ethWeb3.eth.getBalance(account, function(err, balance) { 16 | addBalance(account, ethWeb3.fromWei(balance, 'ether')); 17 | }) 18 | } 19 | }); 20 | } 21 | function addBalance(account, balance) { 22 | console.log(account, balance); 23 | $('#balances').append('') 27 | } 28 | -------------------------------------------------------------------------------- /tutorial-07/Strings.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | library Strings { 4 | 5 | function concat(string _base, string _value) pure internal returns (string) { 6 | bytes memory _baseBytes = bytes(_base); 7 | bytes memory _valueBytes = bytes(_value); 8 | 9 | string memory _tmpValue = new string(_baseBytes.length + _valueBytes.length); 10 | bytes memory _newValue = bytes(_tmpValue); 11 | 12 | uint i; 13 | uint j; 14 | 15 | for(i=0;i<_baseBytes.length;i++) { 16 | _newValue[j++] = _baseBytes[i]; 17 | } 18 | 19 | for(i=0;i<_valueBytes.length;i++) { 20 | _newValue[j++] = _valueBytes[i]; 21 | } 22 | 23 | return string(_newValue); 24 | } 25 | 26 | function strpos(string _base, string _value) pure internal returns (int) { 27 | bytes memory _baseBytes = bytes(_base); 28 | bytes memory _valueBytes = bytes(_value); 29 | 30 | assert(_valueBytes.length == 1); 31 | 32 | for(uint i=0;i<_baseBytes.length;i++) { 33 | if (_baseBytes[i] == _valueBytes[0]) { 34 | return int(i); 35 | } 36 | } 37 | 38 | return -1; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tutorial-11/Token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Token { 4 | string internal _symbol; 5 | string internal _name; 6 | uint8 internal _decimals; 7 | uint internal _totalSupply = 1000; 8 | mapping (address => uint) internal _balanceOf; 9 | mapping (address => mapping (address => uint)) internal _allowances; 10 | 11 | function Token(string symbol, string name, uint8 decimals, uint totalSupply) public { 12 | _symbol = symbol; 13 | _name = name; 14 | _decimals = decimals; 15 | _totalSupply = totalSupply; 16 | } 17 | 18 | function name() public constant returns (string) { 19 | return _name; 20 | } 21 | 22 | function symbol() public constant returns (string) { 23 | return _symbol; 24 | } 25 | 26 | function decimals() public constant returns (uint8) { 27 | return _decimals; 28 | } 29 | 30 | function totalSupply() public constant returns (uint) { 31 | return _totalSupply; 32 | } 33 | 34 | function balanceOf(address _addr) public constant returns (uint); 35 | function transfer(address _to, uint _value) public returns (bool); 36 | event Transfer(address indexed _from, address indexed _to, uint _value); 37 | } -------------------------------------------------------------------------------- /tutorial-10/Token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Token { 4 | string internal _symbol; 5 | string internal _name; 6 | uint8 internal _decimals; 7 | uint internal _totalSupply = 1000; 8 | mapping (address => uint) internal _balanceOf; 9 | mapping (address => mapping (address => uint)) internal _allowances; 10 | 11 | constructor(string symbol, string name, uint8 decimals, uint totalSupply) public { 12 | _symbol = symbol; 13 | _name = name; 14 | _decimals = decimals; 15 | _totalSupply = totalSupply; 16 | } 17 | 18 | function name() public constant returns (string) { 19 | return _name; 20 | } 21 | 22 | function symbol() public constant returns (string) { 23 | return _symbol; 24 | } 25 | 26 | function decimals() public constant returns (uint8) { 27 | return _decimals; 28 | } 29 | 30 | function totalSupply() public constant returns (uint) { 31 | return _totalSupply; 32 | } 33 | 34 | function balanceOf(address _addr) public constant returns (uint); 35 | function transfer(address _to, uint _value) public returns (bool); 36 | event Transfer(address indexed _from, address indexed _to, uint _value); 37 | } 38 | -------------------------------------------------------------------------------- /tutorial-13/Assembly.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Assembly { 4 | function nativeLoops() public returns (uint _r) { 5 | for(uint i = 0; i < 10; i++) { 6 | _r++; 7 | } 8 | } 9 | 10 | function asmLoops() public returns (uint _r) { 11 | assembly { 12 | let i := 0 13 | loop: 14 | i := add(i, 1) 15 | _r := add(_r, 1) 16 | jumpi(loop, lt(i, 10)) 17 | } 18 | } 19 | 20 | function inlineAsmLoops() public returns (uint _r) { 21 | assembly { 22 | 0 // i 23 | 10 // max 24 | 25 | loop: 26 | // i := add(i, 1) 27 | dup2 28 | 1 29 | add 30 | swap2 31 | pop 32 | 33 | // _r := add(_r, 1) 34 | dup3 35 | 1 36 | add 37 | swap3 38 | pop 39 | 40 | // lt(i, 10) 41 | dup1 42 | dup3 43 | lt 44 | 45 | // jumpi(loop, lt(i, 10)) 46 | loop 47 | jumpi 48 | 49 | pop 50 | pop 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /tutorial-31/src/main/resources/solidity/AddressBook.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract AddressBook { 4 | mapping(address => address[]) private _addresses; 5 | mapping(address => mapping(address => string)) private _aliases; 6 | 7 | function getAddresses() public view returns (address[]) { 8 | return _addresses[msg.sender]; 9 | } 10 | 11 | function addAddress(address addr, string alias) public { 12 | _addresses[msg.sender].push(addr); 13 | _aliases[msg.sender][addr] = alias; 14 | } 15 | 16 | function removeAddress(address addr) public { 17 | uint length = _addresses[msg.sender].length; 18 | for(uint i = 0; i < length; i++) { 19 | if (addr == _addresses[msg.sender][i]) { 20 | if (1 < _addresses[msg.sender].length && i < length-1) { 21 | _addresses[msg.sender][i] = _addresses[msg.sender][length-1]; 22 | } 23 | delete _addresses[msg.sender][length-1]; 24 | _addresses[msg.sender].length--; 25 | delete _aliases[msg.sender][addr]; 26 | break; 27 | } 28 | } 29 | } 30 | 31 | function getAlias(address addr) public view returns (string) { 32 | return _aliases[msg.sender][addr]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tutorial-32/src/main/resources/solidity/AddressBook.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract AddressBook { 4 | mapping(address => address[]) private _addresses; 5 | mapping(address => mapping(address => string)) private _aliases; 6 | 7 | function getAddresses() public view returns (address[]) { 8 | return _addresses[msg.sender]; 9 | } 10 | 11 | function addAddress(address addr, string alias) public { 12 | _addresses[msg.sender].push(addr); 13 | _aliases[msg.sender][addr] = alias; 14 | } 15 | 16 | function removeAddress(address addr) public { 17 | uint length = _addresses[msg.sender].length; 18 | for(uint i = 0; i < length; i++) { 19 | if (addr == _addresses[msg.sender][i]) { 20 | if (1 < _addresses[msg.sender].length && i < length-1) { 21 | _addresses[msg.sender][i] = _addresses[msg.sender][length-1]; 22 | } 23 | delete _addresses[msg.sender][length-1]; 24 | _addresses[msg.sender].length--; 25 | delete _aliases[msg.sender][addr]; 26 | break; 27 | } 28 | } 29 | } 30 | 31 | function getAlias(address addr) public view returns (string) { 32 | return _aliases[msg.sender][addr]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tutorial-33/src/main/resources/solidity/AddressBook.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract AddressBook { 4 | mapping(address => address[]) private _addresses; 5 | mapping(address => mapping(address => string)) private _aliases; 6 | 7 | function getAddresses() public view returns (address[]) { 8 | return _addresses[msg.sender]; 9 | } 10 | 11 | function addAddress(address addr, string alias) public { 12 | _addresses[msg.sender].push(addr); 13 | _aliases[msg.sender][addr] = alias; 14 | } 15 | 16 | function removeAddress(address addr) public { 17 | uint length = _addresses[msg.sender].length; 18 | for(uint i = 0; i < length; i++) { 19 | if (addr == _addresses[msg.sender][i]) { 20 | if (1 < _addresses[msg.sender].length && i < length-1) { 21 | _addresses[msg.sender][i] = _addresses[msg.sender][length-1]; 22 | } 23 | delete _addresses[msg.sender][length-1]; 24 | _addresses[msg.sender].length--; 25 | delete _aliases[msg.sender][addr]; 26 | break; 27 | } 28 | } 29 | } 30 | 31 | function getAlias(address addr) public view returns (string) { 32 | return _aliases[msg.sender][addr]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tutorial-28/public/Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | grunt.initConfig({ 4 | pkg: grunt.file.readJSON('package.json'), 5 | browserify: { 6 | js: { 7 | src: 'src/scripts/*.js', 8 | dest: 'build/scripts/app.js', 9 | }, 10 | }, 11 | jshint: { 12 | all: ['Gruntfile.js', 'src/**/*.js'], 13 | options: { 14 | esversion: 6 15 | } 16 | }, 17 | copy: { 18 | all: { 19 | expand: true, 20 | cwd: 'src/', 21 | src: ['**/*.html', '**/*.css'], 22 | dest: 'build/', 23 | }, 24 | }, 25 | watch: { 26 | scripts: { 27 | files: ['src/**'], 28 | tasks: ['jshint','browserify','copy'], 29 | options: { 30 | spawn: false, 31 | }, 32 | } 33 | }, 34 | connect: { 35 | server: { 36 | options: { 37 | port: 8000, 38 | hostname: '*', 39 | base: './build/' 40 | } 41 | } 42 | } 43 | }); 44 | 45 | grunt.loadNpmTasks('grunt-contrib-watch'); 46 | grunt.loadNpmTasks('grunt-contrib-connect'); 47 | grunt.loadNpmTasks('grunt-browserify'); 48 | grunt.loadNpmTasks('grunt-contrib-copy'); 49 | grunt.loadNpmTasks('grunt-contrib-jshint'); 50 | 51 | grunt.registerTask('default', ['jshint','browserify','copy','connect:server','watch']); 52 | }; 53 | -------------------------------------------------------------------------------- /tutorial-12/Assembly.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Assembly { 4 | function nativeLoops() public returns (uint _r) { 5 | for(uint i = 0; i < 10; i++) { 6 | _r++; 7 | } 8 | } 9 | 10 | function asmLoops() public returns (uint _r) { 11 | assembly { 12 | let i := 0 13 | loop: 14 | i := add(i, 1) 15 | _r := add(_r, 1) 16 | jumpi(loop, lt(i, 10)) 17 | } 18 | } 19 | 20 | function nativeConditional(uint _v) public returns (uint) { 21 | if (5 == _v) { 22 | return 55; 23 | } else if (6 == _v) { 24 | return 66; 25 | } 26 | return 11; 27 | } 28 | 29 | function asmConditional(uint _v) public returns (uint _r) { 30 | assembly { 31 | switch _v 32 | case 5 { 33 | _r := 55 34 | } 35 | case 6 { 36 | _r := 66 37 | } 38 | default { 39 | _r := 11 40 | } 41 | } 42 | } 43 | 44 | function asmReturns(uint _v) public returns (uint) { 45 | assembly { 46 | let _ptr := add(msize(), 1) 47 | mstore(_ptr, _v) 48 | return(_ptr, 0x20) 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /tutorial-16/AlarmTrigger.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | interface AlarmWakeUp { 4 | function callback(bytes calldata _data) external; 5 | } 6 | 7 | contract AlarmService { 8 | 9 | struct TimeEvent { 10 | address addr; 11 | bytes data; 12 | } 13 | 14 | mapping(uint => TimeEvent[]) private _events; 15 | 16 | function set(uint _time) 17 | public 18 | returns (bool) { 19 | TimeEvent memory _timeEvent; 20 | _timeEvent.addr = msg.sender; 21 | _timeEvent.data = msg.data; 22 | _events[_time].push(_timeEvent); 23 | } 24 | 25 | function call(uint _time) 26 | public { 27 | TimeEvent[] memory timeEvents = _events[_time]; 28 | for(uint i = 0; i < timeEvents.length; i++) { 29 | AlarmWakeUp(timeEvents[i].addr).callback(timeEvents[i].data); 30 | } 31 | } 32 | } 33 | 34 | contract AlarmTrigger is AlarmWakeUp { 35 | 36 | AlarmService private _alarmService; 37 | 38 | constructor() public { 39 | _alarmService = new AlarmService(); 40 | } 41 | 42 | function callback(bytes memory _data) 43 | public { 44 | // Do something 45 | } 46 | 47 | function setAlarm() 48 | public { 49 | _alarmService.set(block.timestamp+60); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /tutorial-17/Alphabet.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface Letter { 4 | function n() public returns (uint); 5 | } 6 | 7 | contract A is Letter { 8 | function n() 9 | public 10 | returns (uint) { 11 | return 1; 12 | } 13 | } 14 | 15 | contract B is A {} 16 | 17 | contract C is Letter { 18 | function n() 19 | public 20 | returns (uint) { 21 | return 2; 22 | } 23 | 24 | function x() 25 | public 26 | returns (string) { 27 | return "x"; 28 | } 29 | } 30 | 31 | contract Alphabet { 32 | 33 | Letter[] private letters; 34 | 35 | event Printer(uint); 36 | 37 | function Alphabet() 38 | public { 39 | letters.push(new A()); 40 | letters.push(new B()); 41 | letters.push(new C()); 42 | } 43 | 44 | function loadRemote(address _addrX, 45 | address _addrY, 46 | address _addrZ) 47 | public { 48 | letters.push(Letter(_addrX)); 49 | letters.push(Letter(_addrY)); 50 | letters.push(Letter(_addrZ)); 51 | } 52 | 53 | function printLetters() 54 | public { 55 | for(uint i = 0; i < letters.length; i++) { 56 | Printer(letters[i].n()); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /tutorial-22/contracts/Token.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Token { 4 | 5 | string internal _symbol; 6 | string internal _name; 7 | 8 | uint8 internal _decimals; 9 | uint internal _totalSupply; 10 | 11 | mapping (address => uint) internal _balanceOf; 12 | mapping (address => mapping (address => uint)) internal _allowances; 13 | 14 | function Token(string symbol, string name, uint8 decimals, uint totalSupply) public { 15 | _symbol = symbol; 16 | _name = name; 17 | _decimals = decimals; 18 | _totalSupply = totalSupply; 19 | } 20 | 21 | function name() 22 | public 23 | view 24 | returns (string) { 25 | return _name; 26 | } 27 | 28 | function symbol() 29 | public 30 | view 31 | returns (string) { 32 | return _symbol; 33 | } 34 | 35 | function decimals() 36 | public 37 | view 38 | returns (uint8) { 39 | return _decimals; 40 | } 41 | 42 | function totalSupply() 43 | public 44 | view 45 | returns (uint) { 46 | return _totalSupply; 47 | } 48 | 49 | function balanceOf(address _addr) public view returns (uint); 50 | function transfer(address _to, uint _value) public returns (bool); 51 | event Transfer(address indexed _from, address indexed _to, uint _value); 52 | } 53 | -------------------------------------------------------------------------------- /tutorial-06/DataTypes.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract DataTypes { 4 | 5 | bool myBool = false; 6 | 7 | int8 myInt = -128; 8 | uint8 myUInt = 255; 9 | 10 | string myString; 11 | uint8[] myStringArr; 12 | 13 | byte myValue; 14 | bytes1 myBytes1; 15 | bytes32 myBytes32; 16 | 17 | // fixed256x8 myFixed = 1; // 255.0 18 | // ufixed myFixed = 1; 19 | 20 | enum Action {ADD, REMOVE, UPDATE} 21 | 22 | Action myAction = Action.ADD; 23 | 24 | address myAddress; 25 | 26 | function assignAddress() public { 27 | myAddress = msg.sender; 28 | myAddress.balance; 29 | myAddress.transfer(10); 30 | } 31 | 32 | uint[] myIntArr = [1,2,3]; 33 | 34 | function arrFunc() public { 35 | myIntArr.push(1); 36 | myIntArr.length; 37 | myIntArr[0]; 38 | } 39 | 40 | uint[10] myFixedArr; 41 | 42 | struct Account { 43 | uint balance; 44 | uint dailyLimit; 45 | } 46 | 47 | Account myAccount; 48 | 49 | function structFunc() public { 50 | myAccount.balance = 100; 51 | } 52 | 53 | mapping (address => Account) _accounts; 54 | 55 | function () public payable { 56 | _accounts[msg.sender].balance += msg.value; 57 | } 58 | 59 | function getBalance() public view returns (uint) { 60 | return _accounts[msg.sender].balance; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tutorial-16/TimeBased.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract TimeBased { 4 | 5 | mapping(address => uint) public _balanceOf; 6 | mapping(address => uint) public _expiryOf; 7 | 8 | uint private leaseTime = 600; 9 | 10 | modifier expire(address _addr) { 11 | if (_expiryOf[_addr] >= block.timestamp) { 12 | _expiryOf[_addr] = 0; 13 | _balanceOf[_addr] = 0; 14 | } 15 | _; 16 | } 17 | 18 | function lease() 19 | public 20 | payable 21 | expire(msg.sender) 22 | returns (bool) { 23 | require(msg.value == 1 ether); 24 | require(_balanceOf[msg.sender] == 0); 25 | _balanceOf[msg.sender] = 1; 26 | _expiryOf[msg.sender] = block.timestamp + leaseTime; 27 | return true; 28 | } 29 | 30 | function balanceOf() 31 | public 32 | returns (uint) { 33 | return balanceOf(msg.sender); 34 | } 35 | 36 | function balanceOf(address _addr) 37 | public 38 | expire(_addr) 39 | returns (uint) { 40 | return _balanceOf[_addr]; 41 | } 42 | 43 | function expiryOf() 44 | public 45 | returns (uint) { 46 | return expiryOf(msg.sender); 47 | } 48 | 49 | function expiryOf(address _addr) 50 | public 51 | expire(_addr) 52 | returns (uint) { 53 | return _expiryOf[_addr]; 54 | } 55 | } -------------------------------------------------------------------------------- /tutorial-02/myfirstcontract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | interface Regulator { 4 | function checkValue(uint amount) external returns (bool); 5 | function loan() external returns (bool); 6 | } 7 | 8 | contract Bank is Regulator { 9 | uint private value; 10 | 11 | constructor(uint amount) public { 12 | value = amount; 13 | } 14 | 15 | function deposit(uint amount) public { 16 | value += amount; 17 | } 18 | 19 | function withdraw(uint amount) public { 20 | if (checkValue(amount)) { 21 | value -= amount; 22 | } 23 | } 24 | 25 | function balance() public view returns (uint) { 26 | return value; 27 | } 28 | 29 | function checkValue(uint amount) public returns (bool) { 30 | // Classic mistake in the tutorial value should be above the amount 31 | return value >= amount; 32 | } 33 | 34 | function loan() public returns (bool) { 35 | return value > 0; 36 | } 37 | } 38 | 39 | contract MyFirstContract is Bank(10) { 40 | string private name; 41 | uint private age; 42 | 43 | function setName(string memory newName) public { 44 | name = newName; 45 | } 46 | 47 | function getName() public view returns (string memory) { 48 | return name; 49 | } 50 | 51 | function setAge(uint newAge) public { 52 | age = newAge; 53 | } 54 | 55 | function getAge() public view returns (uint) { 56 | return age; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tutorial-28/solidity/contracts/AddressBook.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract AddressBook { 4 | mapping(address => uint) private _state; 5 | mapping(address => address[]) private _addresses; 6 | mapping(address => mapping(address => string)) private _aliases; 7 | 8 | function getAddresses() public view returns (address[]) { 9 | return _addresses[msg.sender]; 10 | } 11 | 12 | function addAddress(address addr, string alias) public { 13 | _addresses[msg.sender].push(addr); 14 | _aliases[msg.sender][addr] = alias; 15 | _state[msg.sender]++; 16 | } 17 | 18 | function removeAddress(address addr) public { 19 | uint length = _addresses[msg.sender].length; 20 | for(uint i = 0; i < length; i++) { 21 | if (addr == _addresses[msg.sender][i]) { 22 | if (1 < _addresses[msg.sender].length && i < length-1) { 23 | _addresses[msg.sender][i] = _addresses[msg.sender][length-1]; 24 | } 25 | delete _addresses[msg.sender][length-1]; 26 | _addresses[msg.sender].length--; 27 | delete _aliases[msg.sender][addr]; 28 | _state[msg.sender]++; 29 | break; 30 | } 31 | } 32 | } 33 | 34 | function getAlias(address addr) public view returns (string) { 35 | return _aliases[msg.sender][addr]; 36 | } 37 | 38 | function getState() public view returns (uint) { 39 | return _state[msg.sender]; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tutorial-24/MultiSigWallet.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract MultiSigWallet { 4 | 5 | address private _owner; 6 | mapping(address => uint8) private _owners; 7 | 8 | modifier isOwner() { 9 | require(msg.sender == _owner); 10 | _; 11 | } 12 | 13 | modifier validOwner() { 14 | require(msg.sender == _owner || _owners[msg.sender] == 1); 15 | _; 16 | } 17 | 18 | event DepositFunds(address from, uint amount); 19 | event WithdrawFunds(address to, uint amount); 20 | event TransferFunds(address from, address to, uint amount); 21 | 22 | constructor() 23 | public { 24 | _owner = msg.sender; 25 | } 26 | 27 | function addOwner(address owner) 28 | isOwner 29 | public { 30 | _owners[owner] = 1; 31 | } 32 | 33 | function removeOwner(address owner) 34 | isOwner 35 | public { 36 | _owners[owner] = 0; 37 | } 38 | 39 | function () 40 | public 41 | payable { 42 | emit DepositFunds(msg.sender, msg.value); 43 | } 44 | 45 | function withdraw(uint amount) 46 | validOwner 47 | public { 48 | require(address(this).balance >= amount); 49 | msg.sender.transfer(amount); 50 | emit WithdrawFunds(msg.sender, amount); 51 | } 52 | 53 | function transferTo(address to, uint amount) 54 | validOwner 55 | public { 56 | require(address(this).balance >= amount); 57 | to.transfer(amount); 58 | emit TransferFunds(msg.sender, to, amount); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /tutorial-28/public/src/scripts/contracts/addressbook.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": true, 4 | "inputs": [], 5 | "name": "getState", 6 | "outputs": [ 7 | { 8 | "name": "", 9 | "type": "uint256" 10 | } 11 | ], 12 | "payable": false, 13 | "stateMutability": "view", 14 | "type": "function" 15 | }, 16 | { 17 | "constant": false, 18 | "inputs": [ 19 | { 20 | "name": "addr", 21 | "type": "address" 22 | } 23 | ], 24 | "name": "removeAddress", 25 | "outputs": [], 26 | "payable": false, 27 | "stateMutability": "nonpayable", 28 | "type": "function" 29 | }, 30 | { 31 | "constant": true, 32 | "inputs": [ 33 | { 34 | "name": "addr", 35 | "type": "address" 36 | } 37 | ], 38 | "name": "getAlias", 39 | "outputs": [ 40 | { 41 | "name": "", 42 | "type": "string" 43 | } 44 | ], 45 | "payable": false, 46 | "stateMutability": "view", 47 | "type": "function" 48 | }, 49 | { 50 | "constant": true, 51 | "inputs": [], 52 | "name": "getAddresses", 53 | "outputs": [ 54 | { 55 | "name": "", 56 | "type": "address[]" 57 | } 58 | ], 59 | "payable": false, 60 | "stateMutability": "view", 61 | "type": "function" 62 | }, 63 | { 64 | "constant": false, 65 | "inputs": [ 66 | { 67 | "name": "addr", 68 | "type": "address" 69 | }, 70 | { 71 | "name": "alias", 72 | "type": "string" 73 | } 74 | ], 75 | "name": "addAddress", 76 | "outputs": [], 77 | "payable": false, 78 | "stateMutability": "nonpayable", 79 | "type": "function" 80 | } 81 | ] 82 | -------------------------------------------------------------------------------- /tutorial-28/public/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Learning Solidity 6 | 7 | 8 | 9 | 10 | 11 |
12 |
Learning Solidity - Tutorial 28
13 | 17 |
18 | 19 |
20 | 21 |
22 |

Address Book

23 |

on the blockchain

24 |
25 | 26 |
27 | 28 |
29 |

Learning Solidity

30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /tutorial-28/public/src/templates/addresses.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |

5 | Address Book 6 | {{addresses.length}} 7 |

8 | 9 | Refresh 10 | 11 |
    12 |
  • 13 |
    14 |
    {{alias}}
    15 | {{address}} 16 | Delete 17 |
    18 |
  • 19 |
20 | 21 | 22 |
23 |
24 |

Add Address

25 |
26 | 27 |
28 | 29 | 30 |
31 | Please enter a valid email address for shipping updates. 32 |
33 |
34 | 35 |
36 | 37 | 38 |
39 | Please enter your shipping address. 40 |
41 |
42 | 43 |
44 | 45 |
46 |
47 |
48 | -------------------------------------------------------------------------------- /tutorial-03/myfirstcontract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface Regulator { 4 | function checkValue(uint amount) external returns (bool); 5 | function loan() external returns (bool); 6 | } 7 | 8 | contract Bank is Regulator { 9 | uint private value; 10 | address private owner; 11 | 12 | modifier ownerFunc { 13 | require(owner == msg.sender); 14 | _; 15 | } 16 | 17 | constructor(uint amount) public { 18 | value = amount; 19 | owner = msg.sender; 20 | } 21 | 22 | function deposit(uint amount) public ownerFunc { 23 | value += amount; 24 | } 25 | 26 | function withdraw(uint amount) public ownerFunc { 27 | if (checkValue(amount)) { 28 | value -= amount; 29 | } 30 | } 31 | 32 | function balance() public view returns (uint) { 33 | return value; 34 | } 35 | 36 | function checkValue(uint amount) public returns (bool) { 37 | // Classic mistake in the tutorial value should be above the amount 38 | return value >= amount; 39 | } 40 | 41 | function loan() public returns (bool) { 42 | return value > 0; 43 | } 44 | } 45 | 46 | contract MyFirstContract is Bank(10) { 47 | string private name; 48 | uint private age; 49 | 50 | function setName(string newName) public { 51 | name = newName; 52 | } 53 | 54 | function getName() public view returns (string) { 55 | return name; 56 | } 57 | 58 | function setAge(uint newAge) public { 59 | age = newAge; 60 | } 61 | 62 | function getAge() public view returns (uint) { 63 | return age; 64 | } 65 | } 66 | 67 | contract TestThrows { 68 | function testAssert() public pure { 69 | assert(1 == 2); 70 | } 71 | 72 | function testRequire() public pure { 73 | require(2 == 1); 74 | } 75 | 76 | function testRevert() public pure { 77 | revert(); 78 | } 79 | 80 | function testThrow() public pure { 81 | throw; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /tutorial-09/MyToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "browser/ERC20.sol"; 4 | 5 | contract MyFirstToken is ERC20 { 6 | string public constant symbol = "MFT"; 7 | string public constant name = "My First Token"; 8 | uint8 public constant decimals = 18; 9 | 10 | uint private constant __totalSupply = 1000; 11 | mapping (address => uint) private __balanceOf; 12 | mapping (address => mapping (address => uint)) private __allowances; 13 | 14 | constructor() public { 15 | __balanceOf[msg.sender] = __totalSupply; 16 | } 17 | 18 | function totalSupply() public constant returns (uint _totalSupply) { 19 | _totalSupply = __totalSupply; 20 | } 21 | 22 | function balanceOf(address _addr) public constant returns (uint balance) { 23 | return __balanceOf[_addr]; 24 | } 25 | 26 | function transfer(address _to, uint _value) public returns (bool success) { 27 | if (_value > 0 && _value <= balanceOf(msg.sender)) { 28 | __balanceOf[msg.sender] -= _value; 29 | __balanceOf[_to] += _value; 30 | return true; 31 | } 32 | return false; 33 | } 34 | 35 | function transferFrom(address _from, address _to, uint _value) public returns (bool success) { 36 | if (__allowances[_from][msg.sender] > 0 && 37 | _value > 0 && 38 | __allowances[_from][msg.sender] >= _value && 39 | __balanceOf[_from] >= _value) { 40 | __balanceOf[_from] -= _value; 41 | __balanceOf[_to] += _value; 42 | // Missed from the video 43 | __allowances[_from][msg.sender] -= _value; 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | function approve(address _spender, uint _value) public returns (bool success) { 50 | __allowances[msg.sender][_spender] = _value; 51 | return true; 52 | } 53 | 54 | function allowance(address _owner, address _spender) public constant returns (uint remaining) { 55 | return __allowances[_owner][_spender]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tutorial-22/contracts/Crowdsale.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "./ERC223ReceivingContract.sol"; 4 | import "./SafeMath.sol"; 5 | import "./ERC20.sol"; 6 | import "./Token.sol"; 7 | 8 | contract Crowdsale is ERC223ReceivingContract { 9 | 10 | using SafeMath for uint; 11 | 12 | Token private _token; 13 | 14 | uint private _start; 15 | uint private _end; 16 | 17 | uint private _price; 18 | uint private _limit; 19 | uint private _available; 20 | 21 | mapping (address => uint) private _limits; 22 | 23 | event Buy(address beneficiary, uint amount); 24 | 25 | modifier available() { 26 | require(_available > 0); 27 | require(block.number >= _start && block.number < _end); 28 | _; 29 | } 30 | 31 | modifier isToken() { 32 | require(msg.sender == address(_token)); 33 | _; 34 | } 35 | 36 | modifier valid(address to, uint amount) { 37 | assert(amount > 0); 38 | amount = amount.div(_price); 39 | assert(_limit >= amount); 40 | assert(_limit >= _limits[to].add(amount)); 41 | _; 42 | } 43 | 44 | function Crowdsale(address token, uint start, uint end, uint price, uint limit) 45 | public { 46 | _token = Token(token); 47 | _start = start; 48 | _end = end; 49 | _price = price; 50 | _limit = limit; 51 | } 52 | 53 | function () 54 | public 55 | payable { 56 | // Not enough gas for the transaction so prevent users from sending ether 57 | revert(); 58 | } 59 | 60 | function buy() 61 | public 62 | payable { 63 | return buyFor(msg.sender); 64 | } 65 | 66 | function buyFor(address beneficiary) 67 | public 68 | available 69 | valid(beneficiary, msg.value) 70 | payable { 71 | uint amount = msg.value.div(_price); 72 | _token.transfer(beneficiary, amount); 73 | _available = _available.sub(amount); 74 | _limits[beneficiary] = _limits[beneficiary].add(amount); 75 | Buy(beneficiary, amount); 76 | } 77 | 78 | function tokenFallback(address, uint _value, bytes) 79 | isToken 80 | public { 81 | _available = _available.add(_value); 82 | } 83 | 84 | function availableBalance() 85 | view 86 | public 87 | returns (uint) { 88 | return _available; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tutorial-28/README.MD: -------------------------------------------------------------------------------- 1 | # Getting going 2 | 3 | ## Ganache + MetaMask 4 | 5 | 1. First, start up Ganache 6 | 2. Click on settings (cog top right) 7 | 3. Go to the "Accounts & Keys" tab 8 | 4. Set the Mnemonic to match the seed words generated by MetaMask under settings and "Reveal Seed Words" 9 | 5. Restart Ganache 10 | 6. Test your Metamask connection to Ganache 11 | 12 | ## Truffle 13 | 14 | You'll first need to set-up the contract before we can continue. 15 | 16 | To build and migrate the contract run the following: 17 | ``` 18 | $ cd solidity 19 | $ truffle migrate 20 | ``` 21 | 22 | Once it has migrated make note of the contract's address. 23 | 24 | The output will look like this: 25 | ``` 26 | Using network 'development'. 27 | 28 | Running migration: 1_initial_migration.js 29 | Deploying Migrations... 30 | ... 0x5231df496194ed312b63b352b48b8ed1d51cf43ca472565d4eebff80a2dcb1e5 31 | Migrations: 0x2411aa047ca7be82a189f8268dfea2009b7ab670 32 | Saving successful migration to network... 33 | ... 0x39712854c026802e7a65af5928a78b1b6309f0e71e14366f6cb286b8907ae33d 34 | Saving artifacts... 35 | Running migration: 2_deploy_contracts.js 36 | Deploying AddressBook... 37 | ... 0xc8f0c50442fe056eb667d20a31ea5f317e92784af10d1c7147e78d5788c50087 38 | AddressBook: 0x897c95fed51d8b89a8a57d8bbe7f1522bf530571 39 | Saving successful migration to network... 40 | ... 0x1c98ffba8159a5eeb0b4af3d51028884c0ca7c611c0213330cbb7573c7268faa 41 | Saving artifacts... 42 | ``` 43 | 44 | You just need the part which says: 45 | 46 | ``` 47 | AddressBook: 0x897c95fed51d8b89a8a57d8bbe7f1522bf530571 48 | ``` 49 | 50 | In `public/src/scripts/controllers/addresses.js` paste this address on line 12 wrapped in quotes. 51 | 52 | This will have also generated a directory called `build`. If you change the structure of the address book contract you will need to: 53 | 1. Inside `solidity/build/contracts/AddressBook.json` there is a json structure, at the first level there is an "abi" object 54 | 2. Copy the entire value of this abi into `public/src/scripts/contracts/addressbook.json` 55 | 56 | ## Node 57 | 58 | Now you've set-up Truffle we can build the web application. 59 | 60 | The first thing we will need to do is get grunt installed by running: 61 | 62 | ``` 63 | $ cd public 64 | $ npm update 65 | $ grunt 66 | ``` 67 | 68 | This will build, minify and serve the application at http://localhost:8000 -------------------------------------------------------------------------------- /tutorial-31/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /tutorial-32/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /tutorial-33/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /tutorial-21/test/metacoin.js: -------------------------------------------------------------------------------- 1 | var MetaCoin = artifacts.require("./MetaCoin.sol"); 2 | 3 | contract('MetaCoin', function(accounts) { 4 | it("should put 10000 MetaCoin in the first account", function() { 5 | return MetaCoin.deployed().then(function(instance) { 6 | return instance.getBalance.call(accounts[0]); 7 | }).then(function(balance) { 8 | assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account"); 9 | }); 10 | }); 11 | it("should call a function that depends on a linked library", function() { 12 | var meta; 13 | var metaCoinBalance; 14 | var metaCoinEthBalance; 15 | 16 | return MetaCoin.deployed().then(function(instance) { 17 | meta = instance; 18 | return meta.getBalance.call(accounts[0]); 19 | }).then(function(outCoinBalance) { 20 | metaCoinBalance = outCoinBalance.toNumber(); 21 | return meta.getBalanceInEth.call(accounts[0]); 22 | }).then(function(outCoinBalanceEth) { 23 | metaCoinEthBalance = outCoinBalanceEth.toNumber(); 24 | }).then(function() { 25 | assert.equal(metaCoinEthBalance, 2 * metaCoinBalance, "Library function returned unexpected function, linkage may be broken"); 26 | }); 27 | }); 28 | it("should send coin correctly", function() { 29 | var meta; 30 | 31 | // Get initial balances of first and second account. 32 | var account_one = accounts[0]; 33 | var account_two = accounts[1]; 34 | 35 | var account_one_starting_balance; 36 | var account_two_starting_balance; 37 | var account_one_ending_balance; 38 | var account_two_ending_balance; 39 | 40 | var amount = 10; 41 | 42 | return MetaCoin.deployed().then(function(instance) { 43 | meta = instance; 44 | return meta.getBalance.call(account_one); 45 | }).then(function(balance) { 46 | account_one_starting_balance = balance.toNumber(); 47 | return meta.getBalance.call(account_two); 48 | }).then(function(balance) { 49 | account_two_starting_balance = balance.toNumber(); 50 | return meta.sendCoin(account_two, amount, {from: account_one}); 51 | }).then(function() { 52 | return meta.getBalance.call(account_one); 53 | }).then(function(balance) { 54 | account_one_ending_balance = balance.toNumber(); 55 | return meta.getBalance.call(account_two); 56 | }).then(function(balance) { 57 | account_two_ending_balance = balance.toNumber(); 58 | 59 | assert.equal(account_one_ending_balance, account_one_starting_balance - amount, "Amount wasn't correctly taken from the sender"); 60 | assert.equal(account_two_ending_balance, account_two_starting_balance + amount, "Amount wasn't correctly sent to the receiver"); 61 | }); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /tutorial-22/test/TestMyToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "truffle/Assert.sol"; 4 | import "../contracts/MyToken.sol"; 5 | 6 | contract TestMyToken { 7 | 8 | MyToken private _myToken; 9 | address private _owner; 10 | 11 | function TestMyToken() public { 12 | _owner = msg.sender; 13 | } 14 | 15 | function beforeEach() public { 16 | _myToken = new MyToken(); 17 | } 18 | 19 | function test_constructor() public { 20 | uint allocatedTokens = _myToken.balanceOf(this); 21 | Assert.equal(allocatedTokens, 10000, "Contract creator should hold 10000 tokens"); 22 | } 23 | 24 | function test_transfer_withValidAmount() public { 25 | _myToken.transfer(_owner, 100); 26 | uint transferredTokens = _myToken.balanceOf(_owner); 27 | uint allocatedTokens = _myToken.balanceOf(this); 28 | Assert.equal(transferredTokens, 100, "Recipient should hold 100 tokens"); 29 | Assert.equal(allocatedTokens, 9900, "Contract creator should hold 9900 tokens"); 30 | } 31 | 32 | function test_transfer_withInvalidAmount() public { 33 | bool transferSuccessful = _myToken.transfer(_owner, 10001); 34 | Assert.equal(transferSuccessful, false, "Addresses should not be able to transfer more tokens than allocated"); 35 | } 36 | 37 | function test_totalSupply() public { 38 | uint totalSupply = _myToken.totalSupply(); 39 | Assert.equal(totalSupply, 10000, "There should be 10000 tokens in circulation"); 40 | } 41 | 42 | function test_transferFrom_withInvalidAllocation() public { 43 | _myToken.transfer(_owner, 100); 44 | bool transferSuccessful = _myToken.transferFrom(_owner, this, 100); 45 | Assert.equal(transferSuccessful, false, "Unauthorised addresses should not be able to transfer tokens"); 46 | } 47 | 48 | function test_approve_withValidAmount() public { 49 | bool allocationSuccessful = _myToken.approve(_owner, 100); 50 | Assert.equal(allocationSuccessful, true, "Token owner should be able to allocate less than or equal to their holdings"); 51 | } 52 | 53 | function test_approve_withInvalidAmount() public { 54 | bool allocationSuccessful = _myToken.approve(_owner, 10001); 55 | Assert.equal(allocationSuccessful, false, "Token owner should not be able to allocate more than their holdings"); 56 | } 57 | 58 | function test_allowance_withNoAllocatedBalance() public { 59 | uint allowanceAvailable = _myToken.allowance(_owner, this); 60 | Assert.equal(allowanceAvailable, 0, "Spender should not have a balance available"); 61 | } 62 | 63 | function test_allowance_withAllocatedBalance() public { 64 | _myToken.approve(_owner, 100); 65 | uint allowanceAvailable = _myToken.allowance(_owner, this); 66 | Assert.equal(allowanceAvailable, 0, "Spender should have a balance of 100 available"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tutorial-32/src/main/java/youtube/solidity/learning/Main.java: -------------------------------------------------------------------------------- 1 | package youtube.solidity.learning; 2 | 3 | import org.web3j.crypto.CipherException; 4 | import org.web3j.crypto.Credentials; 5 | import org.web3j.crypto.WalletUtils; 6 | import org.web3j.protocol.Web3j; 7 | import org.web3j.protocol.core.methods.response.TransactionReceipt; 8 | import org.web3j.protocol.core.methods.response.Web3ClientVersion; 9 | import org.web3j.protocol.http.HttpService; 10 | import org.web3j.tx.RawTransactionManager; 11 | import org.web3j.tx.TransactionManager; 12 | import org.web3j.tx.Transfer; 13 | import org.web3j.utils.Convert; 14 | 15 | import java.io.IOException; 16 | import java.math.BigDecimal; 17 | import java.math.BigInteger; 18 | 19 | public class Main { 20 | 21 | private final static String PRIVATE_KEY = "087db5d7c2647f17e4d028f65d46babac4525eb7f810fec992a3eac10cc53ae1"; 22 | 23 | private final static BigInteger GAS_LIMIT = BigInteger.valueOf(6721975L); 24 | private final static BigInteger GAS_PRICE = BigInteger.valueOf(20000000000L); 25 | 26 | private final static String RECIPIENT = "0x466B6E82CD017923298Db45C5a3Db7c66Cd753C8"; 27 | 28 | public static void main(String[] args) { 29 | try { 30 | new Main(); 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | 36 | private Main() throws Exception { 37 | Web3j web3j = Web3j.build(new HttpService()); 38 | 39 | TransactionManager transactionManager = new RawTransactionManager( 40 | web3j, 41 | getCredentialsFromPrivateKey() 42 | ); 43 | 44 | Transfer transfer = new Transfer(web3j, transactionManager); 45 | 46 | TransactionReceipt transactionReceipt = transfer.sendFunds( 47 | RECIPIENT, 48 | BigDecimal.ONE, 49 | Convert.Unit.ETHER, 50 | GAS_PRICE, 51 | GAS_LIMIT 52 | ).send(); 53 | 54 | System.out.print("Transaction = " + transactionReceipt.getTransactionHash()); 55 | } 56 | 57 | private void printWeb3Version(Web3j web3j) { 58 | Web3ClientVersion web3ClientVersion = null; 59 | try { 60 | web3ClientVersion = web3j.web3ClientVersion().send(); 61 | } catch (IOException e) { 62 | e.printStackTrace(); 63 | } 64 | String web3ClientVersionString = web3ClientVersion.getWeb3ClientVersion(); 65 | System.out.println("Web3 client version: " + web3ClientVersionString); 66 | } 67 | 68 | private Credentials getCredentialsFromWallet() throws IOException, CipherException { 69 | return WalletUtils.loadCredentials( 70 | "passphrase", 71 | "wallet/path" 72 | ); 73 | } 74 | 75 | private Credentials getCredentialsFromPrivateKey() { 76 | return Credentials.create(PRIVATE_KEY); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tutorial-10/MyFirstToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "browser/Token.sol"; 4 | import "browser/ERC20.sol"; 5 | import "browser/ERC223.sol"; 6 | import "browser/ERC223ReceivingContract.sol"; 7 | 8 | contract MyFirstToken is Token("MFT", "My First Token", 18, 1000), ERC20, ERC223 { 9 | 10 | constructor() public { 11 | _balanceOf[msg.sender] = _totalSupply; 12 | } 13 | 14 | function totalSupply() public constant returns (uint) { 15 | return _totalSupply; 16 | } 17 | 18 | function balanceOf(address _addr) public constant returns (uint) { 19 | return _balanceOf[_addr]; 20 | } 21 | 22 | function transfer(address _to, uint _value) public returns (bool) { 23 | if (_value > 0 && 24 | _value <= _balanceOf[msg.sender] && 25 | !isContract(_to)) { 26 | _balanceOf[msg.sender] -= _value; 27 | _balanceOf[_to] += _value; 28 | emit Transfer(msg.sender, _to, _value); 29 | return true; 30 | } 31 | return false; 32 | } 33 | 34 | function transfer(address _to, uint _value, bytes _data) public returns (bool) { 35 | if (_value > 0 && 36 | _value <= _balanceOf[msg.sender] && 37 | isContract(_to)) { 38 | _balanceOf[msg.sender] -= _value; 39 | _balanceOf[_to] += _value; 40 | ERC223ReceivingContract _contract = ERC223ReceivingContract(_to); 41 | _contract.tokenFallback(msg.sender, _value, _data); 42 | emit Transfer(msg.sender, _to, _value, _data); 43 | return true; 44 | } 45 | return false; 46 | } 47 | 48 | function isContract(address _addr) public view returns (bool) { 49 | uint codeSize; 50 | assembly { 51 | codeSize := extcodesize(_addr) 52 | } 53 | return codeSize > 0; 54 | } 55 | 56 | function transferFrom(address _from, address _to, uint _value) public returns (bool) { 57 | if (_allowances[_from][msg.sender] > 0 && 58 | _value > 0 && 59 | _allowances[_from][msg.sender] >= _value && 60 | _balanceOf[_from] >= _value) { 61 | _balanceOf[_from] -= _value; 62 | _balanceOf[_to] += _value; 63 | _allowances[_from][msg.sender] -= _value; 64 | emit Transfer(_from, _to, _value); 65 | return true; 66 | } 67 | return false; 68 | } 69 | 70 | function approve(address _spender, uint _value) public returns (bool) { 71 | _allowances[msg.sender][_spender] = _value; 72 | emit Approval(msg.sender, _spender, _value); 73 | return true; 74 | } 75 | 76 | function allowance(address _owner, address _spender) public constant returns (uint) { 77 | return _allowances[_owner][_spender]; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tutorial-22/test/TestMyToken.js: -------------------------------------------------------------------------------- 1 | var MyToken = artifacts.require("./MyToken.sol"); 2 | 3 | contract('MyToken', (accounts) => { 4 | 5 | var creatorAddress = accounts[0]; 6 | var recipientAddress = accounts[1]; 7 | var delegatedAddress = accounts[2]; 8 | 9 | it("should contain 10000 MyToken in circulation", () => { 10 | return MyToken.deployed().then((instance) => { 11 | return instance.totalSupply.call(); 12 | }).then(balance => { 13 | assert.equal(balance.valueOf(), 10000, "10000 MyToken are not in circulation"); 14 | }); 15 | }); 16 | 17 | it("should contain 10000 MyToken in the creator balance", () => { 18 | return MyToken.deployed().then(instance => { 19 | return instance.balanceOf.call(creatorAddress); 20 | }).then(balance => { 21 | assert.equal(balance.valueOf(), 10000, "10000 wasn't in the creator balance"); 22 | }); 23 | }); 24 | 25 | it("should transfer 1000 MyToken to the recipient balance", () => { 26 | var myTokenInstance; 27 | return MyToken.deployed().then(instance => { 28 | myTokenInstance = instance; 29 | return myTokenInstance.transfer(recipientAddress, 1000, {from: creatorAddress}); 30 | }).then(result => { 31 | return myTokenInstance.balanceOf.call(recipientAddress); 32 | }).then(recipientBalance => { 33 | assert.equal(recipientBalance.valueOf(), 1000, "1000 wasn't in the recipient balance"); 34 | return myTokenInstance.balanceOf.call(creatorAddress); 35 | }).then(creatorBalance => { 36 | assert.equal(creatorBalance.valueOf(), 9000, "9000 wasn't in the creator balance"); 37 | }); 38 | }); 39 | 40 | it("should approve 500 MyToken to the delegated balance", () => { 41 | var myTokenInstance; 42 | return MyToken.deployed().then(instance => { 43 | myTokenInstance = instance; 44 | return myTokenInstance.approve(delegatedAddress, 500, {from: creatorAddress}); 45 | }).then(result => { 46 | return myTokenInstance.allowance.call(creatorAddress, delegatedAddress); 47 | }).then(delegatedAllowance => { 48 | assert.equal(delegatedAllowance.valueOf(), 500, "500 wasn't approved to the delegated balance"); 49 | }); 50 | }); 51 | 52 | it("should transfer 200 MyToken from the creator to the alt recipient via the delegated address", () => { 53 | var myTokenInstance; 54 | return MyToken.deployed().then(instance => { 55 | myTokenInstance = instance; 56 | return myTokenInstance.transferFrom(creatorAddress, recipientAddress, 200, {from: delegatedAddress}); 57 | }).then(result => { 58 | return myTokenInstance.balanceOf.call(recipientAddress); 59 | }).then(recipientBalance => { 60 | assert.equal(recipientBalance.valueOf(), 1200, "1200 wasn't in the recipient balance"); 61 | return myTokenInstance.allowance.call(creatorAddress, delegatedAddress); 62 | }).then(delegatedAllowance => { 63 | assert.equal(delegatedAllowance.valueOf(), 300, "300 wasn't set as the delegated balance"); 64 | }); 65 | }); 66 | 67 | }); 68 | -------------------------------------------------------------------------------- /tutorial-18/Casino.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Casino { 4 | 5 | uint private start; 6 | 7 | uint private buyPeriod = 1000; 8 | uint private verifyPeriod = 100; 9 | uint private checkPeriod = 100; 10 | 11 | mapping(address => uint) private _tickets; 12 | mapping(address => uint) private _winnings; 13 | 14 | address[] _entries; 15 | address[] _verified; 16 | 17 | uint private winnerSeed; 18 | bool private hasWinner; 19 | address private winner; 20 | 21 | function Casino() 22 | public { 23 | start = block.timestamp; 24 | } 25 | 26 | /** 27 | * This should NOT be part of the contract!! 28 | */ 29 | function unsafeEntry(uint number, uint salt) 30 | public 31 | payable 32 | returns (bool) { 33 | return buyTicket(generateHash(number, salt)); 34 | } 35 | 36 | function generateHash(uint number, uint salt) 37 | public 38 | pure 39 | returns (uint) { 40 | return uint(keccak256(number + salt)); 41 | } 42 | 43 | function buyTicket(uint hash) 44 | public 45 | payable 46 | returns (bool) { 47 | // Within the timeframe 48 | require(block.timestamp < start+buyPeriod); 49 | // Correct amount 50 | require(1 ether == msg.value); 51 | // 1 entry per address 52 | require(_tickets[msg.sender] == 0); 53 | _tickets[msg.sender] = hash; 54 | _entries.push(msg.sender); 55 | return true; 56 | } 57 | 58 | function verifyTicket(uint number, uint salt) 59 | public 60 | returns (bool) { 61 | // Within the timeframe 62 | require(block.timestamp >= start+buyPeriod); 63 | require(block.timestamp < start+buyPeriod+verifyPeriod); 64 | // Has a valid entry 65 | require(_tickets[msg.sender] > 0); 66 | // Validate hash 67 | require(salt > number); 68 | require(generateHash(number, salt) == _tickets[msg.sender]); 69 | winnerSeed = winnerSeed ^ salt ^ uint(msg.sender); 70 | _verified.push(msg.sender); 71 | } 72 | 73 | function checkWinner() 74 | public 75 | returns (bool) { 76 | // Within the timeframe 77 | require(block.timestamp >= start+buyPeriod+verifyPeriod); 78 | require(block.timestamp < start+buyPeriod+verifyPeriod+checkPeriod); 79 | if (!hasWinner) { 80 | winner = _verified[winnerSeed % _verified.length]; 81 | _winnings[winner] = _verified.length-10 ether; 82 | hasWinner = true; 83 | } 84 | return msg.sender == winner; 85 | } 86 | 87 | function claim() 88 | public { 89 | // Has winnings to claim 90 | require(_winnings[msg.sender] > 0); 91 | uint claimAmount = _winnings[msg.sender]; 92 | _winnings[msg.sender] = 0; 93 | msg.sender.transfer(claimAmount); 94 | } 95 | } -------------------------------------------------------------------------------- /tutorial-28/public/src/scripts/controllers/addresses.js: -------------------------------------------------------------------------------- 1 | angular.module('learningSolidity.controllers.addresses', ['ngRoute']) 2 | .config(['$routeProvider', function ($routeProvider) { 3 | $routeProvider 4 | .when('/addresses', { 5 | templateUrl: 'templates/addresses.html', 6 | controller: 'addressesController' 7 | }); 8 | }]) 9 | .controller("addressesController", ['$scope', 'EthereumContract', function ($scope, EthereumContract) { 10 | var addressBook = EthereumContract.contract( 11 | require('../contracts/addressbook.json'), 12 | '0x897c95fed51d8b89a8a57d8bbe7f1522bf530571' 13 | ); 14 | 15 | var ethWeb3 = new Web3(web3.currentProvider); 16 | 17 | $scope.addresses = {}; 18 | 19 | var params = { 20 | from: ethWeb3.eth.accounts[0], 21 | gas: "3000000" 22 | }; 23 | 24 | $scope.add = function () { 25 | addAddress( 26 | $scope.address, 27 | $scope.alias 28 | ); 29 | }; 30 | 31 | $scope.remove = function (address) { 32 | removeAddress(address); 33 | }; 34 | 35 | $scope.getAddresses = function (address) { 36 | getAddresses(address); 37 | }; 38 | 39 | var addAddress = function (address, alias) { 40 | addressBook.addAddress(address, alias, params) 41 | .then(function () { 42 | $scope.addresses[address] = alias; 43 | $scope.$apply(); 44 | }) 45 | .catch(console.error); 46 | }; 47 | 48 | var removeAddress = function (address) { 49 | addressBook.removeAddress(address, params) 50 | .then(function () { 51 | delete $scope.addresses[address]; 52 | $scope.$apply(); 53 | }) 54 | .catch(console.error); 55 | }; 56 | 57 | var getAddresses = function () { 58 | $scope.addresses = {}; 59 | addressBook.getAddresses(params) 60 | .then(function (addresses) { 61 | for (var i in addresses['0']) { 62 | getAlias(addresses['0'][i], params); 63 | } 64 | }) 65 | .catch(console.error); 66 | }; 67 | 68 | var getAlias = function (address) { 69 | addressBook.getAlias(address, params) 70 | .then(function (alias) { 71 | $scope.addresses[address] = alias['0']; 72 | $scope.$apply(); 73 | }) 74 | .catch(console.error); 75 | }; 76 | 77 | var getState = function () { 78 | addressBook.getState(address, params) 79 | .then(function (state) { 80 | $scope.state = state['0']; 81 | $scope.$apply(); 82 | }) 83 | .catch(console.error); 84 | }; 85 | 86 | getAddresses(); 87 | }]); 88 | -------------------------------------------------------------------------------- /tutorial-11/MyFirstToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "Token.sol"; 4 | import "ERC20.sol"; 5 | import "ERC223.sol"; 6 | import "ERC223ReceivingContract.sol"; 7 | import "github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol"; 8 | 9 | contract MyFirstToken is Token("MFT", "My First Token", 18, 1000), ERC20, ERC223 { 10 | 11 | using SafeMath for uint; 12 | 13 | function MyFirstToken() public { 14 | _balanceOf[msg.sender] = _totalSupply; 15 | } 16 | 17 | function totalSupply() public constant returns (uint) { 18 | return _totalSupply; 19 | } 20 | 21 | function balanceOf(address _addr) public constant returns (uint) { 22 | return _balanceOf[_addr]; 23 | } 24 | 25 | function transfer(address _to, uint _value) public returns (bool) { 26 | if (_value > 0 && 27 | _value <= _balanceOf[msg.sender] && 28 | !isContract(_to)) { 29 | _balanceOf[msg.sender] =_balanceOf[msg.sender].sub(_value); 30 | _balanceOf[_to] = _balanceOf[_to].add(_value); 31 | Transfer(msg.sender, _to, _value); 32 | return true; 33 | } 34 | return false; 35 | } 36 | 37 | function transfer(address _to, uint _value, bytes _data) public returns (bool) { 38 | if (_value > 0 && 39 | _value <= _balanceOf[msg.sender] && 40 | isContract(_to)) { 41 | _balanceOf[msg.sender] = _balanceOf[msg.sender].sub(_value); 42 | _balanceOf[_to] = _balanceOf[_to].add(_value); 43 | ERC223ReceivingsolsasdasdasContract _contract = ERC223ReceivingContract(_to); 44 | _contract.tokenFallback(msg.sender, _value, _data); 45 | Transfer(msg.sender, _to, _value, _data); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | function isContract(address _addr) private constant returns (bool) { 52 | uint codeSize; 53 | assembly { 54 | codeSize := extcodesize(_addr) 55 | } 56 | return codeSize > 0; 57 | } 58 | 59 | function transferFrom(address _from, address _to, uint _value) public returns (bool) { 60 | if (_allowances[_from][msg.sender] > 0 && 61 | _value > 0 && 62 | _allowances[_from][msg.sender] >= _value && 63 | _balanceOf[_from] >= _value) { 64 | _balanceOf[_from] = _balanceOf[_from].sub(_value); 65 | _balanceOf[_to] = _balanceOf[_to].add(_value); 66 | _allowances[_from][msg.sender] -= _value; 67 | Transfer(_from, _to, _value); 68 | return true; 69 | } 70 | return false; 71 | } 72 | 73 | function approve(address _spender, uint _value) public returns (bool) { 74 | _allowances[msg.sender][_spender] = _value; 75 | Approval(msg.sender, _spender, _value); 76 | return true; 77 | } 78 | 79 | function allowance(address _owner, address _spender) public constant returns (uint) { 80 | return _allowances[_owner][_spender]; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tutorial-31/src/main/resources/out/AddressBook.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b50610639806100206000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ba79dfe811461006657806399900d1114610089578063a39fac121461011f578063d033c45614610184575b600080fd5b34801561007257600080fd5b50610087600160a060020a03600435166101eb565b005b34801561009557600080fd5b506100aa600160a060020a0360043516610386565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e45781810151838201526020016100cc565b50505050905090810190601f1680156101115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012b57600080fd5b50610134610438565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610170578181015183820152602001610158565b505050509050019250505060405180910390f35b34801561019057600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610087958335600160a060020a03169536956044949193909101919081908401838280828437509497506104a29650505050505050565b33600090815260208190526040812054905b818110156103815733600090815260208190526040902080548290811061022057fe5b600091825260209091200154600160a060020a03848116911614156103795733600090815260208190526040902054600110801561026057506001820381105b156102e5573360009081526020819052604090208054600019840190811061028457fe5b60009182526020808320909101543383529082905260409091208054600160a060020a0390921691839081106102b657fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b3360009081526020819052604090208054600019840190811061030457fe5b60009182526020808320909101805473ffffffffffffffffffffffffffffffffffffffff191690553382528190526040902080549061034790600019830161050a565b50336000908152600160209081526040808320600160a060020a038716845290915281206103749161052e565b610381565b6001016101fd565b505050565b336000908152600160208181526040808420600160a060020a038616855282529283902080548451600294821615610100026000190190911693909304601f8101839004830284018301909452838352606093909183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b336000908152602081815260409182902080548351818402810184019094528084526060939283018282801561049757602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610479575b505050505090505b90565b3360008181526020818152604080832080546001808201835591855283852001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0389169081179091559484528252808320938352928152919020825161038192840190610575565b815481835581811115610381576000838152602090206103819181019083016105f3565b50805460018160011615610100020316600290046000825580601f106105545750610572565b601f01602090049060005260206000209081019061057291906105f3565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b657805160ff19168380011785556105e3565b828001600101855582156105e3579182015b828111156105e35782518255916020019190600101906105c8565b506105ef9291506105f3565b5090565b61049f91905b808211156105ef57600081556001016105f95600a165627a7a7230582002b4cd1de8dbad4668d406cbb6ac585b72bbd2cfc54d016da10df49ff42ea9e90029 -------------------------------------------------------------------------------- /tutorial-32/src/main/resources/out/AddressBook.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b50610639806100206000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ba79dfe811461006657806399900d1114610089578063a39fac121461011f578063d033c45614610184575b600080fd5b34801561007257600080fd5b50610087600160a060020a03600435166101eb565b005b34801561009557600080fd5b506100aa600160a060020a0360043516610386565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e45781810151838201526020016100cc565b50505050905090810190601f1680156101115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012b57600080fd5b50610134610438565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610170578181015183820152602001610158565b505050509050019250505060405180910390f35b34801561019057600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610087958335600160a060020a03169536956044949193909101919081908401838280828437509497506104a29650505050505050565b33600090815260208190526040812054905b818110156103815733600090815260208190526040902080548290811061022057fe5b600091825260209091200154600160a060020a03848116911614156103795733600090815260208190526040902054600110801561026057506001820381105b156102e5573360009081526020819052604090208054600019840190811061028457fe5b60009182526020808320909101543383529082905260409091208054600160a060020a0390921691839081106102b657fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b3360009081526020819052604090208054600019840190811061030457fe5b60009182526020808320909101805473ffffffffffffffffffffffffffffffffffffffff191690553382528190526040902080549061034790600019830161050a565b50336000908152600160209081526040808320600160a060020a038716845290915281206103749161052e565b610381565b6001016101fd565b505050565b336000908152600160208181526040808420600160a060020a038616855282529283902080548451600294821615610100026000190190911693909304601f8101839004830284018301909452838352606093909183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b336000908152602081815260409182902080548351818402810184019094528084526060939283018282801561049757602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610479575b505050505090505b90565b3360008181526020818152604080832080546001808201835591855283852001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0389169081179091559484528252808320938352928152919020825161038192840190610575565b815481835581811115610381576000838152602090206103819181019083016105f3565b50805460018160011615610100020316600290046000825580601f106105545750610572565b601f01602090049060005260206000209081019061057291906105f3565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b657805160ff19168380011785556105e3565b828001600101855582156105e3579182015b828111156105e35782518255916020019190600101906105c8565b506105ef9291506105f3565b5090565b61049f91905b808211156105ef57600081556001016105f95600a165627a7a7230582002b4cd1de8dbad4668d406cbb6ac585b72bbd2cfc54d016da10df49ff42ea9e90029 -------------------------------------------------------------------------------- /tutorial-33/src/main/resources/out/AddressBook.bin: -------------------------------------------------------------------------------- 1 | 608060405234801561001057600080fd5b50610639806100206000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ba79dfe811461006657806399900d1114610089578063a39fac121461011f578063d033c45614610184575b600080fd5b34801561007257600080fd5b50610087600160a060020a03600435166101eb565b005b34801561009557600080fd5b506100aa600160a060020a0360043516610386565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e45781810151838201526020016100cc565b50505050905090810190601f1680156101115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012b57600080fd5b50610134610438565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610170578181015183820152602001610158565b505050509050019250505060405180910390f35b34801561019057600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610087958335600160a060020a03169536956044949193909101919081908401838280828437509497506104a29650505050505050565b33600090815260208190526040812054905b818110156103815733600090815260208190526040902080548290811061022057fe5b600091825260209091200154600160a060020a03848116911614156103795733600090815260208190526040902054600110801561026057506001820381105b156102e5573360009081526020819052604090208054600019840190811061028457fe5b60009182526020808320909101543383529082905260409091208054600160a060020a0390921691839081106102b657fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b3360009081526020819052604090208054600019840190811061030457fe5b60009182526020808320909101805473ffffffffffffffffffffffffffffffffffffffff191690553382528190526040902080549061034790600019830161050a565b50336000908152600160209081526040808320600160a060020a038716845290915281206103749161052e565b610381565b6001016101fd565b505050565b336000908152600160208181526040808420600160a060020a038616855282529283902080548451600294821615610100026000190190911693909304601f8101839004830284018301909452838352606093909183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b336000908152602081815260409182902080548351818402810184019094528084526060939283018282801561049757602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610479575b505050505090505b90565b3360008181526020818152604080832080546001808201835591855283852001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0389169081179091559484528252808320938352928152919020825161038192840190610575565b815481835581811115610381576000838152602090206103819181019083016105f3565b50805460018160011615610100020316600290046000825580601f106105545750610572565b601f01602090049060005260206000209081019061057291906105f3565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b657805160ff19168380011785556105e3565b828001600101855582156105e3579182015b828111156105e35782518255916020019190600101906105c8565b506105ef9291506105f3565b5090565b61049f91905b808211156105ef57600081556001016105f95600a165627a7a7230582002b4cd1de8dbad4668d406cbb6ac585b72bbd2cfc54d016da10df49ff42ea9e90029 -------------------------------------------------------------------------------- /tutorial-22/test/TestCrowdsale.js: -------------------------------------------------------------------------------- 1 | var Crowdsale = artifacts.require("./Crowdsale.sol"); 2 | var MyToken = artifacts.require("./MyToken.sol"); 3 | 4 | contract('Crowdsale', (accounts) => { 5 | 6 | var creatorAddress = accounts[0]; 7 | var recipientAddress = accounts[1]; 8 | 9 | var crowdsaleAddress; 10 | Crowdsale.deployed().then(instance => { 11 | crowdsaleAddress = instance.address; 12 | }); 13 | 14 | var myTokenAddress; 15 | MyToken.deployed().then(instance => { 16 | myTokenAddress = instance.address; 17 | }); 18 | 19 | it("should transfer 1000 MyToken to the crowdsale balance", () => { 20 | var myTokenInstance; 21 | return MyToken.deployed().then(instance => { 22 | myTokenInstance = instance; 23 | return myTokenInstance.transfer(crowdsaleAddress, 1000, {from: creatorAddress}); 24 | }).then(result => { 25 | return myTokenInstance.balanceOf.call(crowdsaleAddress); 26 | }).then(crowdsaleBalance => { 27 | assert.equal(crowdsaleBalance.valueOf(), 1000, "1000 wasn't in the crowdsale balance"); 28 | }); 29 | }); 30 | 31 | it("should have a crowdsale balance of 1000", () => { 32 | return Crowdsale.deployed().then(instance => { 33 | return instance.availableBalance.call(); 34 | }).then(availableBalance => { 35 | assert.equal(availableBalance.valueOf(), 1000, "1000 wasn't the available crowdsale balance"); 36 | }); 37 | }); 38 | 39 | it("should transfer 1 token to the creator address", () => { 40 | var crowdsaleInstance; 41 | return Crowdsale.deployed().then(instance => { 42 | crowdsaleInstance = instance; 43 | return crowdsaleInstance.buy({from: creatorAddress, value: web3.toWei(1, 'ether')}); 44 | }).then(result => { 45 | return crowdsaleInstance.availableBalance.call(); 46 | }).then(availableBalance => { 47 | assert.equal(availableBalance.valueOf(), 999, "999 wasn't the available crowdsale balance"); 48 | }); 49 | }); 50 | 51 | it("should contain 9001 MyToken in the creator balance", () => { 52 | return MyToken.deployed().then(instance => { 53 | return instance.balanceOf.call(creatorAddress); 54 | }).then(balance => { 55 | assert.equal(balance.valueOf(), 9001, "9001 wasn't in the creator balance"); 56 | }); 57 | }); 58 | 59 | it("should transfer 1 token to the recipient address", () => { 60 | var crowdsaleInstance; 61 | return Crowdsale.deployed().then(instance => { 62 | crowdsaleInstance = instance; 63 | return crowdsaleInstance.buyFor(recipientAddress, {from: creatorAddress, value: web3.toWei(1, 'ether')}); 64 | }).then(result => { 65 | return crowdsaleInstance.availableBalance.call(); 66 | }).then(availableBalance => { 67 | assert.equal(availableBalance.valueOf(), 998, "998 wasn't the available crowdsale balance"); 68 | }); 69 | }); 70 | 71 | it("should contain 1 MyToken in the recipient balance", () => { 72 | return MyToken.deployed().then(instance => { 73 | return instance.balanceOf.call(recipientAddress); 74 | }).then(balance => { 75 | assert.equal(balance.valueOf(), 1, "1 wasn't in the recipient balance"); 76 | }); 77 | }); 78 | }); 79 | -------------------------------------------------------------------------------- /tutorial-19/NestedArrays.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract NestedArrays { 4 | 5 | uint[][] private nested; 6 | 7 | function getArray() public { 8 | nested.push([1,2,3]); 9 | } 10 | 11 | // [1, 3, 2, 4] 12 | function toBytes(uint[] _array) 13 | public 14 | returns (bytes _ptr) { 15 | assembly { 16 | let len := mload(_array) 17 | _ptr := msize() 18 | 19 | // Bytes 20 | mstore(_ptr, mul(add(len, 2), 0x20)) 21 | 22 | // Array 23 | mstore(add(_ptr, 0x20), 0x20) 24 | mstore(add(_ptr, 0x40), len) 25 | 26 | let idx := 0 27 | loop: 28 | jumpi(end, eq(len, idx)) 29 | mstore(add(_ptr, add(mul(idx,0x20),0x60)), mload(add(_array, add(0x20, mul(idx, 0x20))))) 30 | idx := add(idx, 1) 31 | jump(loop) 32 | 33 | end: 34 | // Without return statements memory is overridden 35 | mstore(0x40, add(mul(len, 0x20), 0x20)) 36 | } 37 | } 38 | 39 | // ["0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x20","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x04","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x01","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x03","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x02","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x00","0x04"] 40 | function toArray(bytes _bytes) 41 | public 42 | returns (uint[] _ptr) { 43 | assembly { 44 | 45 | // First 32 bytes are byte array properties 46 | // Next 32 bytes are the data size of the array elements 47 | let len := mload(add(_bytes, 0x40)) 48 | _ptr := msize() 49 | 50 | // Array 51 | mstore(_ptr, len) 52 | 53 | let idx := 0 54 | loop: 55 | jumpi(end, eq(len, idx)) 56 | mstore(add(_ptr, add(mul(idx,0x20),0x20)), mload(add(_bytes, add(0x60, mul(idx, 0x20))))) 57 | idx := add(idx, 1) 58 | jump(loop) 59 | 60 | end: 61 | mstore(0x40, add(_ptr,add(mul(len, 0x20), 0x40))) 62 | } 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /tutorial-27/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Learning Solidity 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 25 |
26 | 27 |
28 | 29 |
30 |

Ethereum Balance

31 |
32 | 33 |
34 | 35 |
36 | 37 |
38 | 39 | 54 | 55 |
56 | 57 |
58 | 59 | 62 | 63 | 66 | 67 | 77 | 78 |
79 | 80 |
81 | 82 |
83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /tutorial-22/contracts/MyToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | import "./Token.sol"; 4 | import "./ERC20.sol"; 5 | import "./ERC223.sol"; 6 | import "./ERC223ReceivingContract.sol"; 7 | import "./SafeMath.sol"; 8 | import "./Addresses.sol"; 9 | 10 | contract MyToken is Token("MFT", "My Token", 0, 10000), ERC20, ERC223 { 11 | 12 | using SafeMath for uint; 13 | using Addresses for address; 14 | 15 | function MyToken() 16 | public { 17 | _balanceOf[msg.sender] = _totalSupply; 18 | } 19 | 20 | function totalSupply() 21 | public 22 | view 23 | returns (uint) { 24 | return _totalSupply; 25 | } 26 | 27 | function balanceOf(address _addr) 28 | public 29 | view 30 | returns (uint) { 31 | return _balanceOf[_addr]; 32 | } 33 | 34 | function transfer(address _to, uint _value) 35 | public 36 | returns (bool) { 37 | return transfer(_to, _value, ""); 38 | } 39 | 40 | function transfer(address _to, uint _value, bytes _data) 41 | public 42 | returns (bool) { 43 | if (_value > 0 && 44 | _value <= _balanceOf[msg.sender]) { 45 | 46 | if (_to.isContract()) { 47 | ERC223ReceivingContract _contract = ERC223ReceivingContract(_to); 48 | _contract.tokenFallback(msg.sender, _value, _data); 49 | } 50 | 51 | _balanceOf[msg.sender] = _balanceOf[msg.sender].sub(_value); 52 | _balanceOf[_to] = _balanceOf[_to].add(_value); 53 | 54 | return true; 55 | } 56 | return false; 57 | } 58 | 59 | function transferFrom(address _from, address _to, uint _value) 60 | public 61 | returns (bool) { 62 | return transferFrom(_from, _to, _value, ""); 63 | } 64 | 65 | function transferFrom(address _from, address _to, uint _value, bytes _data) 66 | public 67 | returns (bool) { 68 | if (_allowances[_from][msg.sender] > 0 && 69 | _value > 0 && 70 | _allowances[_from][msg.sender] >= _value && 71 | _balanceOf[_from] >= _value) { 72 | 73 | _allowances[_from][msg.sender] -= _value; 74 | 75 | if (_to.isContract()) { 76 | ERC223ReceivingContract _contract = ERC223ReceivingContract(_to); 77 | _contract.tokenFallback(msg.sender, _value, _data); 78 | } 79 | 80 | _balanceOf[_from] = _balanceOf[_from].sub(_value); 81 | _balanceOf[_to] = _balanceOf[_to].add(_value); 82 | 83 | Transfer(_from, _to, _value); 84 | 85 | return true; 86 | } 87 | return false; 88 | } 89 | 90 | function approve(address _spender, uint _value) 91 | public 92 | returns (bool) { 93 | if (_balanceOf[msg.sender] >= _value) { 94 | _allowances[msg.sender][_spender] = _value; 95 | Approval(msg.sender, _spender, _value); 96 | return true; 97 | } 98 | return false; 99 | } 100 | 101 | function allowance(address _owner, address _spender) 102 | public 103 | view 104 | returns (uint) { 105 | if (_allowances[_owner][_spender] < _balanceOf[_owner]) { 106 | return _allowances[_owner][_spender]; 107 | } 108 | return _balanceOf[_owner]; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tutorial-25/contracts/MultiSigWallet.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract MultiSigWallet { 4 | 5 | address private _owner; 6 | mapping(address => uint8) private _owners; 7 | 8 | uint constant MIN_SIGNATURES = 2; 9 | uint private _transactionIdx; 10 | 11 | struct Transaction { 12 | address from; 13 | address to; 14 | uint amount; 15 | uint8 signatureCount; 16 | mapping (address => uint8) signatures; 17 | } 18 | 19 | mapping (uint => Transaction) private _transactions; 20 | uint[] private _pendingTransactions; 21 | 22 | modifier isOwner() { 23 | require(msg.sender == _owner); 24 | _; 25 | } 26 | 27 | modifier validOwner() { 28 | require(msg.sender == _owner || _owners[msg.sender] == 1); 29 | _; 30 | } 31 | 32 | event DepositFunds(address from, uint amount); 33 | event TransactionCreated(address from, address to, uint amount, uint transactionId); 34 | event TransactionCompleted(address from, address to, uint amount, uint transactionId); 35 | event TransactionSigned(address by, uint transactionId); 36 | 37 | function MultiSigWallet() 38 | public { 39 | _owner = msg.sender; 40 | } 41 | 42 | function addOwner(address owner) 43 | isOwner 44 | public { 45 | _owners[owner] = 1; 46 | } 47 | 48 | function removeOwner(address owner) 49 | isOwner 50 | public { 51 | _owners[owner] = 0; 52 | } 53 | 54 | function () 55 | public 56 | payable { 57 | DepositFunds(msg.sender, msg.value); 58 | } 59 | 60 | function withdraw(uint amount) 61 | public { 62 | transferTo(msg.sender, amount); 63 | } 64 | 65 | function transferTo(address to, uint amount) 66 | validOwner 67 | public { 68 | require(address(this).balance >= amount); 69 | uint transactionId = _transactionIdx++; 70 | 71 | Transaction memory transaction; 72 | transaction.from = msg.sender; 73 | transaction.to = to; 74 | transaction.amount = amount; 75 | transaction.signatureCount = 0; 76 | 77 | _transactions[transactionId] = transaction; 78 | _pendingTransactions.push(transactionId); 79 | 80 | TransactionCreated(msg.sender, to, amount, transactionId); 81 | } 82 | 83 | function getPendingTransactions() 84 | view 85 | validOwner 86 | public 87 | returns (uint[]) { 88 | return _pendingTransactions; 89 | } 90 | 91 | function signTransaction(uint transactionId) 92 | validOwner 93 | public { 94 | 95 | Transaction storage transaction = _transactions[transactionId]; 96 | 97 | // Transaction must exist 98 | require(0x0 != transaction.from); 99 | // Creator cannot sign the transaction 100 | require(msg.sender != transaction.from); 101 | // Cannot sign a transaction more than once 102 | require(transaction.signatures[msg.sender] != 1); 103 | 104 | transaction.signatures[msg.sender] = 1; 105 | transaction.signatureCount++; 106 | 107 | TransactionSigned(msg.sender, transactionId); 108 | 109 | if (transaction.signatureCount >= MIN_SIGNATURES) { 110 | require(address(this).balance >= transaction.amount); 111 | transaction.to.transfer(transaction.amount); 112 | TransactionCompleted(transaction.from, transaction.to, transaction.amount, transactionId); 113 | deleteTransaction(transactionId); 114 | } 115 | } 116 | 117 | function deleteTransaction(uint transactionId) 118 | validOwner 119 | public { 120 | uint8 replace = 0; 121 | for(uint i = 0; i < _pendingTransactions.length; i++) { 122 | if (1 == replace) { 123 | _pendingTransactions[i-1] = _pendingTransactions[i]; 124 | } else if (transactionId == _pendingTransactions[i]) { 125 | replace = 1; 126 | } 127 | } 128 | delete _pendingTransactions[_pendingTransactions.length - 1]; 129 | _pendingTransactions.length--; 130 | delete _transactions[transactionId]; 131 | } 132 | 133 | function walletBalance() 134 | constant 135 | public 136 | returns (uint) { 137 | return address(this).balance; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Learning Solidity 2 | The companion to the Youtube tutorials 3 | 4 | ### Videos 5 | 6 | - [Learning Solidity : Tutorial 1 The Basics](https://www.youtube.com/watch?v=v_hU0jPtLto) 7 | - [Learning Solidity : Tutorial 2 Inheritance](https://www.youtube.com/watch?v=6hkmLOtIq8A) 8 | - [Learning Solidity : Tutorial 3 Custom Modifiers and Error Handling](https://www.youtube.com/watch?v=3ObTNzDM3wI) 9 | - [Learning Solidity : Tutorial 4 Imports and Libraries](https://www.youtube.com/watch?v=0Lyf_3kA3Ms) 10 | - [Learning Solidity : Tutorial 5 Event logging and Transaction Information](https://www.youtube.com/watch?v=Jlq997yOoRs) 11 | - [Learning Solidity : Tutorial 6 Data Types (Array, Mapping, Struct)](https://www.youtube.com/watch?v=8UhO3IKApSg) 12 | - [Learning Solidity : Tutorial 7 Extending String Functionality and Bytes](https://www.youtube.com/watch?v=6iiWwT0O2fY) 13 | - [Learning Solidity : Tutorial 8 Debugging Solidity Using Remix](https://www.youtube.com/watch?v=7z52hP26MFs) 14 | - [Learning Solidity : Tutorial 9 ERC20 Tokens and Creating your own Crypto Currency](https://www.youtube.com/watch?v=r7XojpIDuhA) 15 | - [Learning Solidity : Tutorial 10 ERC223 Tokens and Creating your own Crypto Currency](https://www.youtube.com/watch?v=IWC9-yGoDGs) 16 | - [Learning Solidity : Tutorial 11 Deploying Tokens and Creating your own Crypto Currency](https://www.youtube.com/watch?v=WfkPTyvOL_g) 17 | - [Learning Solidity : Tutorial 12 Functional Assembly](https://www.youtube.com/watch?v=nkGN6GwkMzU) 18 | - [Learning Solidity : Tutorial 13 Instructional Assembly](https://www.youtube.com/watch?v=axZJ2NFMH5Q) 19 | - [Learning Solidity : Tutorial 14 Transferring Ethereum between contracts](https://www.youtube.com/watch?v=ELWSKMcJfI8) 20 | - [Learning Solidity : Tutorial 15 Public vs External](https://www.youtube.com/watch?v=Ii4g38mPPlg) 21 | - [Learning Solidity : Tutorial 16 Time Based Events](https://www.youtube.com/watch?v=HGw-yalqdgs) 22 | - [Learning Solidity : Tutorial 17 Polymorphism](https://www.youtube.com/watch?v=l_E5F5qnbtk) 23 | - [Learning Solidity : Tutorial 18 Randomness and Gambling](https://www.youtube.com/watch?v=3wY5PRliphE) 24 | - [Learning Solidity : Tutorial 19 Nested Arrays and Storage](https://www.youtube.com/watch?v=zkNHRJEuYQg) 25 | - [Learning Solidity : Tutorial 20 Parameter Mapping and Multiple Return Values](https://www.youtube.com/watch?v=v3aoiTh-UVQ) 26 | - [Learning Solidity : Tutorial 21 Truffle, Atom and TestRPC](https://www.youtube.com/watch?v=YcTSilIfih0) 27 | - [Learning Solidity : Tutorial 22 Developing an ICO/Crowdsale with TDD](https://www.youtube.com/watch?v=Cow_aL7NUGY) 28 | - [Learning Solidity : Tutorial 23 State Modifiers (view, pure, constant)](https://www.youtube.com/watch?v=RKos31UueqY) 29 | - [Learning Solidity : Tutorial 24 Multisig Wallet](https://www.youtube.com/watch?v=OwavQTuHoM8) 30 | - [Learning Solidity : Tutorial 25 Multisig Wallet cont. Multi Authentication](https://www.youtube.com/watch?v=23YLeX7mpbU) 31 | - [Learning Solidity : Tutorial 26 Auditing, Security and Testing (Long, but important)](https://www.youtube.com/watch?v=LGCMZ7S_ITE) 32 | - [Learning Solidity : Tutorial 27 Getting started with browser development using Metamask](https://www.youtube.com/watch?v=eog2eYrPEu0) 33 | - [Learning Solidity : Tutorial 28 Address book on the blockchain powered by Angular](https://www.youtube.com/watch?v=bvxKICus3bw) 34 | - [Learning Solidity : Tutorial 29 What is WEI and how is Ether defined?](https://www.youtube.com/watch?v=yOfYNUQVjxk) 35 | - [Learning Solidity : Tutorial 30 Gas Explained](https://www.youtube.com/watch?v=sPrYkYk_Beo) 36 | - [Learning Solidity : Tutorial 31 Interacting with RPC using Java and web3j](https://www.youtube.com/watch?v=fzUGvU2dXxU) 37 | - [Learning Solidity : Tutorial 32 Transferring ether with Java using web3j](https://www.youtube.com/watch?v=kJ905hVbQ_E) 38 | - [Learning Solidity : Tutorial 33 Deploying and using a contract using Java and web3j](https://www.youtube.com/watch?v=ibAh04Csp0M) 39 | 40 | ### Support 41 | 42 | - [Invalid implicit conversion of arrays from storage to memory and vice-versa](https://github.com/willitscale/learning-solidity/blob/master/support/INVALID_IMPLICIT_CONVERSION_OF_ARRAYS.MD) 43 | - [UnimplementedFeatureError: Nested arrays not implemented?](https://github.com/willitscale/learning-solidity/blob/master/support/NESTED_ARRAYS_NOT_IMPLEMENTED.MD) 44 | 45 | ### Contributions 46 | 47 | - [Nikita Chebykin](https://github.com/chebykin) 48 | - [Shubham Singh](https://github.com/imshubhamsingh) 49 | - [Shubham Tatvamasi](https://github.com/ShubhamTatvamasi) 50 | - [vardhanapoorv](https://github.com/vardhanapoorv) 51 | - [Kashish Khullar](https://github.com/kashishkhullar) 52 | 53 | -------------------------------------------------------------------------------- /tutorial-26/test/TestMultiSigWallet.js: -------------------------------------------------------------------------------- 1 | var MultiSigWallet = artifacts.require("./MultiSigWallet.sol"); 2 | 3 | contract('MultiSigWallet', (accounts) => { 4 | var creatorAddress = accounts[0]; 5 | var firstOwnerAddress = accounts[1]; 6 | var secondOwnerAddress = accounts[2]; 7 | var externalAddress = accounts[3]; 8 | 9 | it('should revert the transaction of addOwner when an invalid address calls it', () => { 10 | return MultiSigWallet.deployed() 11 | .then(instance => { 12 | return instance.addOwner(firstOwnerAddress, {from:externalAddress}); 13 | }) 14 | .then(result => { 15 | assert.fail(); 16 | }) 17 | .catch(error => { 18 | assert.notEqual(error.message, "assert.fail()", "Transaction was not reverted with an invalid address"); 19 | }); 20 | }); 21 | 22 | it('should revert the transaction of removeOwner when an invalid address calls it', () => { 23 | return MultiSigWallet.deployed() 24 | .then(instance => { 25 | return instance.removeOwner(firstOwnerAddress, {from:externalAddress}); 26 | }) 27 | .then(result => { 28 | assert.fail(); 29 | }) 30 | .catch(error => { 31 | assert.notEqual(error.message, "assert.fail()", "Transaction was not reverted with an invalid address"); 32 | }); 33 | }); 34 | 35 | it('should not revert the transaction of owner modification by the creator address', () => { 36 | var multiSigWalletInstance; 37 | return MultiSigWallet.deployed() 38 | .then(instance => { 39 | multiSigWalletInstance = instance; 40 | return multiSigWalletInstance.removeOwner(creatorAddress); 41 | }) 42 | .then(removedResult => { 43 | return multiSigWalletInstance.addOwner(creatorAddress); 44 | }) 45 | .catch(error => { 46 | assert.fail("Transaction was reverted by a creator call"); 47 | }); 48 | }); 49 | 50 | it('should revert the transaction of deleteTransaction on an invalid transaction ID', () => { 51 | return MultiSigWallet.deployed() 52 | .then(instance => { 53 | return instance.deleteTransaction(1); 54 | }) 55 | .then(result => { 56 | assert.fail(); 57 | }) 58 | .catch(error => { 59 | assert.notEqual(error.message, "assert.fail()", "Transaction was not reverted with an invalid transaction ID passed"); 60 | }) 61 | }); 62 | 63 | it('should revert the transaction if the creator of a pending transaction tries to sign the transaction', () => { 64 | var multiSigWalletInstance; 65 | return MultiSigWallet.deployed() 66 | .then(instance => { 67 | multiSigWalletInstance = instance; 68 | return multiSigWalletInstance.sendTransaction({from: creatorAddress, value: 1000}) 69 | }) 70 | .then(sendResult => { 71 | return multiSigWalletInstance.withdraw(100); 72 | }) 73 | .then(withdrawResult => { 74 | return multiSigWalletInstance.signTransaction(0); 75 | }) 76 | .then(signResult => { 77 | assert.fail(); 78 | }) 79 | .catch(error => { 80 | assert.notEqual(error.message, "assert.fail()", "Transaction was not reverted after creator signed a transaction"); 81 | }); 82 | }); 83 | 84 | it('should revert the transaction if the signer of a pending transaction tries to sign the transaction again', () => { 85 | var multiSigWalletInstance; 86 | return MultiSigWallet.deployed() 87 | .then(instance => { 88 | multiSigWalletInstance = instance; 89 | return multiSigWalletInstance.sendTransaction({from: creatorAddress, value: 1000}) 90 | }) 91 | .then(transferResult => { 92 | return multiSigWalletInstance.addOwner(firstOwnerAddress); 93 | }) 94 | .then(addOwnerResult => { 95 | return multiSigWalletInstance.withdraw(100, {from: firstOwnerAddress}); 96 | }) 97 | .then(firstWithdrawResult => { 98 | return multiSigWalletInstance.signTransaction(1); 99 | }) 100 | .then(secondWithdrawResult => { 101 | return multiSigWalletInstance.signTransaction(1); 102 | }) 103 | .then(signResult => { 104 | assert.fail(); 105 | }) 106 | .catch(error => { 107 | assert.notEqual(error.message, "assert.fail()", "Transaction was not reverted after creator signed a transaction"); 108 | }); 109 | }); 110 | 111 | }); 112 | -------------------------------------------------------------------------------- /tutorial-26/contracts/MultiSigWallet.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract MultiSigWallet { 4 | 5 | address private _owner; 6 | mapping(address => uint8) private _owners; 7 | 8 | uint _transactionIdx; 9 | uint[] private _pendingTransactions; 10 | 11 | struct Transaction { 12 | address from; 13 | address to; 14 | uint amount; 15 | uint8 signatureCount; 16 | mapping (address => uint8) signatures; 17 | } 18 | 19 | mapping(uint => Transaction) _transactions; 20 | uint8 constant private _sigRequiredCount = 2; 21 | 22 | modifier validOwner() { 23 | require(msg.sender == _owner || _owners[msg.sender] == 1); 24 | //require(_owners[msg.sender] == 1); 25 | _; 26 | } 27 | 28 | event DepositFunds(address from, uint amount); 29 | event TransactionCreated(address from, address to, uint amount, uint transactionId); 30 | event TransactionCompleted(address from, address to, uint amount, uint transactionId); 31 | event TransactionSigned(address by, uint transactionId); 32 | 33 | function MultiSigWallet() 34 | public { 35 | // Set master contract owner 36 | _owner = msg.sender; 37 | //_owners[msg.sender] = 1; 38 | } 39 | 40 | function addOwner(address owner) 41 | // isOwner 42 | validOwner 43 | public { 44 | _owners[owner] = 1; 45 | } 46 | 47 | function removeOwner(address owner) 48 | // isOwner 49 | // The owner validation was missing 50 | validOwner 51 | public { 52 | _owners[owner] = 0; 53 | } 54 | 55 | function () 56 | public 57 | payable { 58 | DepositFunds(msg.sender, msg.value); 59 | } 60 | 61 | function send() 62 | public 63 | payable{} 64 | 65 | function withdraw(uint amount) 66 | validOwner 67 | public { 68 | transferTo(msg.sender, amount); 69 | } 70 | 71 | function transferTo(address to, uint amount) 72 | validOwner 73 | public { 74 | require(address(this).balance >= amount); 75 | uint transactionId = _transactionIdx++; 76 | Transaction memory transaction; 77 | transaction.from = msg.sender; 78 | transaction.to = to; 79 | transaction.amount = amount; 80 | transaction.signatureCount = 0; 81 | _transactions[transactionId] = transaction; 82 | _pendingTransactions.push(transactionId); 83 | TransactionCreated(msg.sender, to, amount, transactionId); 84 | } 85 | 86 | function getActiveTransactions() 87 | validOwner 88 | view 89 | public 90 | returns (uint[]) { 91 | return _pendingTransactions; 92 | } 93 | 94 | function signTransaction(uint transactionId) 95 | validOwner 96 | public { 97 | 98 | Transaction storage transaction = _transactions[transactionId]; 99 | 100 | // Transaction must exist 101 | require(0x0 != transaction.from); 102 | //Creator cannot sign this 103 | require(msg.sender != transaction.from); 104 | // Has not already signed this transaction 105 | require(transaction.signatures[msg.sender] == 0); 106 | 107 | transaction.signatures[msg.sender] = 1; 108 | transaction.signatureCount++; 109 | 110 | TransactionSigned(msg.sender, transactionId); 111 | 112 | if (transaction.signatureCount >= _sigRequiredCount) { 113 | require(address(this).balance >= transaction.amount); 114 | transaction.to.transfer(transaction.amount); 115 | TransactionCompleted(msg.sender, transaction.to, transaction.amount, transactionId); 116 | deleteTransaction(transactionId); 117 | } 118 | } 119 | 120 | function deleteTransaction(uint transactionId) 121 | validOwner 122 | public { 123 | uint8 replace = 0; 124 | require(_pendingTransactions.length > 0); 125 | for(uint i = 0; i < _pendingTransactions.length; i++) { 126 | if (1 == replace) { 127 | _pendingTransactions[i-1] = _pendingTransactions[i]; 128 | } else if (_pendingTransactions[i] == transactionId) { 129 | replace = 1; 130 | } 131 | } 132 | assert(replace == 1); 133 | // Created an Overflow 134 | delete _pendingTransactions[_pendingTransactions.length - 1]; 135 | _pendingTransactions.length--; 136 | delete _transactions[transactionId]; 137 | } 138 | 139 | function getPendingTransactionLength() 140 | public 141 | view 142 | returns (uint) { 143 | return _pendingTransactions.length; 144 | } 145 | 146 | function walletBalance() 147 | constant 148 | public returns (uint) { 149 | return address(this).balance; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /tutorial-33/src/main/java/youtube/solidity/learning/Main.java: -------------------------------------------------------------------------------- 1 | package youtube.solidity.learning; 2 | 3 | import org.web3j.crypto.CipherException; 4 | import org.web3j.crypto.Credentials; 5 | import org.web3j.crypto.WalletUtils; 6 | import org.web3j.protocol.Web3j; 7 | import org.web3j.protocol.core.methods.response.TransactionReceipt; 8 | import org.web3j.protocol.core.methods.response.Web3ClientVersion; 9 | import org.web3j.protocol.http.HttpService; 10 | import org.web3j.tx.RawTransactionManager; 11 | import org.web3j.tx.TransactionManager; 12 | import org.web3j.tx.Transfer; 13 | import org.web3j.utils.Convert; 14 | import youtube.solidity.learning.contracts.AddressBook; 15 | 16 | import java.io.IOException; 17 | import java.math.BigDecimal; 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | public class Main { 22 | 23 | private final static String PRIVATE_KEY = "087db5d7c2647f17e4d028f65d46babac4525eb7f810fec992a3eac10cc53ae1"; 24 | 25 | private final static BigInteger GAS_LIMIT = BigInteger.valueOf(6721975L); 26 | private final static BigInteger GAS_PRICE = BigInteger.valueOf(20000000000L); 27 | 28 | private final static String RECIPIENT = "0x466B6E82CD017923298Db45C5a3Db7c66Cd753C8"; 29 | 30 | private final static String CONTRACT_ADDRESS = "0x2cf178c0fcf153dd0f40db1af064824a8c6751a5"; 31 | 32 | public static void main(String[] args) { 33 | try { 34 | new Main(); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | 40 | private Main() throws Exception { 41 | Web3j web3j = Web3j.build(new HttpService()); 42 | 43 | Credentials credentials = getCredentialsFromPrivateKey(); 44 | 45 | AddressBook addressBook = loadContract(CONTRACT_ADDRESS, web3j, credentials); 46 | 47 | removeAddress(addressBook); 48 | 49 | printAddresses(addressBook); 50 | } 51 | 52 | private void printWeb3Version(Web3j web3j) { 53 | Web3ClientVersion web3ClientVersion = null; 54 | try { 55 | web3ClientVersion = web3j.web3ClientVersion().send(); 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | } 59 | String web3ClientVersionString = web3ClientVersion.getWeb3ClientVersion(); 60 | System.out.println("Web3 client version: " + web3ClientVersionString); 61 | } 62 | 63 | private Credentials getCredentialsFromWallet() throws IOException, CipherException { 64 | return WalletUtils.loadCredentials( 65 | "passphrase", 66 | "wallet/path" 67 | ); 68 | } 69 | 70 | private Credentials getCredentialsFromPrivateKey() { 71 | return Credentials.create(PRIVATE_KEY); 72 | } 73 | 74 | private void transferEthereum(Web3j web3j, Credentials credentials) throws Exception { 75 | TransactionManager transactionManager = new RawTransactionManager( 76 | web3j, 77 | credentials 78 | ); 79 | 80 | Transfer transfer = new Transfer(web3j, transactionManager); 81 | 82 | TransactionReceipt transactionReceipt = transfer.sendFunds( 83 | RECIPIENT, 84 | BigDecimal.ONE, 85 | Convert.Unit.ETHER, 86 | GAS_PRICE, 87 | GAS_LIMIT 88 | ).send(); 89 | 90 | System.out.print("Transaction = " + transactionReceipt.getTransactionHash()); 91 | } 92 | 93 | private String deployContract(Web3j web3j, Credentials credentials) throws Exception { 94 | return AddressBook.deploy(web3j, credentials, GAS_PRICE, GAS_LIMIT) 95 | .send() 96 | .getContractAddress(); 97 | } 98 | 99 | private AddressBook loadContract(String contractAddress, Web3j web3j, Credentials credentials) { 100 | return AddressBook.load(contractAddress, web3j, credentials, GAS_PRICE, GAS_LIMIT); 101 | } 102 | 103 | private void addAddresses(AddressBook addressBook) throws Exception { 104 | addressBook 105 | .addAddress("0x256a04B9F02036Ed2f785D8f316806411D605285", "Tom") 106 | .send(); 107 | 108 | addressBook 109 | .addAddress("0x82CDf5a3192f2930726637e9C738A78689a91Be3", "Susan") 110 | .send(); 111 | 112 | addressBook 113 | .addAddress("0x95F57F1DD015ddE7Ec2CbC8212D0ae2faC9acA11", "Bob") 114 | .send(); 115 | } 116 | 117 | private void printAddresses(AddressBook addressBook) throws Exception { 118 | for (Object address : addressBook.getAddresses().send()) { 119 | String addressString = address.toString(); 120 | String alias = addressBook.getAlias(addressString).send(); 121 | System.out.println("Address " + addressString + " aliased as " + alias); 122 | } 123 | } 124 | 125 | private void removeAddress(AddressBook addressBook) throws Exception { 126 | addressBook 127 | .removeAddress("0x256a04B9F02036Ed2f785D8f316806411D605285") 128 | .send(); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /tutorial-11/Compiled.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | interface ERC20 { 4 | function transferFrom(address _from, address _to, uint _value) public returns (bool); 5 | function approve(address _spender, uint _value) public returns (bool); 6 | function allowance(address _owner, address _spender) public constant returns (uint); 7 | event Approval(address indexed _owner, address indexed _spender, uint _value); 8 | } 9 | 10 | interface ERC223 { 11 | function transfer(address _to, uint _value, bytes _data) public returns (bool); 12 | event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); 13 | } 14 | 15 | contract ERC223ReceivingContract { 16 | function tokenFallback(address _from, uint _value, bytes _data) public; 17 | } 18 | 19 | contract Token { 20 | string internal _symbol; 21 | string internal _name; 22 | uint8 internal _decimals; 23 | uint internal _totalSupply = 1000; 24 | mapping (address => uint) internal _balanceOf; 25 | mapping (address => mapping (address => uint)) internal _allowances; 26 | 27 | function Token(string symbol, string name, uint8 decimals, uint totalSupply) public { 28 | _symbol = symbol; 29 | _name = name; 30 | _decimals = decimals; 31 | _totalSupply = totalSupply; 32 | } 33 | 34 | function name() public constant returns (string) { 35 | return _name; 36 | } 37 | 38 | function symbol() public constant returns (string) { 39 | return _symbol; 40 | } 41 | 42 | function decimals() public constant returns (uint8) { 43 | return _decimals; 44 | } 45 | 46 | function totalSupply() public constant returns (uint) { 47 | return _totalSupply; 48 | } 49 | 50 | function balanceOf(address _addr) public constant returns (uint); 51 | function transfer(address _to, uint _value) public returns (bool); 52 | event Transfer(address indexed _from, address indexed _to, uint _value); 53 | } 54 | 55 | library SafeMath { 56 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 57 | uint256 c = a * b; 58 | assert(a == 0 || c / a == b); 59 | return c; 60 | } 61 | 62 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 63 | // assert(b > 0); // Solidity automatically throws when dividing by 0 64 | uint256 c = a / b; 65 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 66 | return c; 67 | } 68 | 69 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 70 | assert(b <= a); 71 | return a - b; 72 | } 73 | 74 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 75 | uint256 c = a + b; 76 | assert(c >= a); 77 | return c; 78 | } 79 | } 80 | 81 | contract MyFirstToken is Token("MFT", "My First Token", 18, 1000), ERC20, ERC223 { 82 | 83 | using SafeMath for uint; 84 | 85 | function MyFirstToken() public { 86 | _balanceOf[msg.sender] = _totalSupply; 87 | } 88 | 89 | function totalSupply() public constant returns (uint) { 90 | return _totalSupply; 91 | } 92 | 93 | function balanceOf(address _addr) public constant returns (uint) { 94 | return _balanceOf[_addr]; 95 | } 96 | 97 | function transfer(address _to, uint _value) public returns (bool) { 98 | if (_value > 0 && 99 | _value <= _balanceOf[msg.sender] && 100 | !isContract(_to)) { 101 | _balanceOf[msg.sender] = _balanceOf[msg.sender].sub(_value); 102 | _balanceOf[_to] = _balanceOf[_to].add(_value); 103 | Transfer(msg.sender, _to, _value); 104 | return true; 105 | } 106 | return false; 107 | } 108 | 109 | function transfer(address _to, uint _value, bytes _data) public returns (bool) { 110 | if (_value > 0 && 111 | _value <= _balanceOf[msg.sender] && 112 | isContract(_to)) { 113 | _balanceOf[msg.sender] = _balanceOf[msg.sender].sub(_value); 114 | _balanceOf[_to] = _balanceOf[_to].add(_value); 115 | ERC223ReceivingContract _contract = ERC223ReceivingContract(_to); 116 | _contract.tokenFallback(msg.sender, _value, _data); 117 | Transfer(msg.sender, _to, _value, _data); 118 | return true; 119 | } 120 | return false; 121 | } 122 | 123 | function isContract(address _addr) private constant returns (bool) { 124 | uint codeSize; 125 | assembly { 126 | codeSize := extcodesize(_addr) 127 | } 128 | return codeSize > 0; 129 | } 130 | 131 | function transferFrom(address _from, address _to, uint _value) public returns (bool) { 132 | if (_allowances[_from][msg.sender] > 0 && 133 | _value > 0 && 134 | _allowances[_from][msg.sender] >= _value && 135 | _balanceOf[_from] >= _value) { 136 | _balanceOf[_from] = _balanceOf[_from].sub(_value); 137 | _balanceOf[_to] = _balanceOf[_to].add(_value); 138 | _allowances[_from][msg.sender] = _allowances[_from][msg.sender].sub(_value); 139 | Transfer(_from, _to, _value); 140 | return true; 141 | } 142 | return false; 143 | } 144 | 145 | function approve(address _spender, uint _value) public returns (bool) { 146 | _allowances[msg.sender][_spender] = _allowances[msg.sender][_spender].add(_value); 147 | Approval(msg.sender, _spender, _value); 148 | return true; 149 | } 150 | 151 | function allowance(address _owner, address _spender) public constant returns (uint) { 152 | return _allowances[_owner][_spender]; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /tutorial-31/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /tutorial-32/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /tutorial-33/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /tutorial-31/src/main/java/youtube/solidity/learning/contracts/AddressBook.java: -------------------------------------------------------------------------------- 1 | package youtube.solidity.learning.contracts; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.concurrent.Callable; 8 | import org.web3j.abi.TypeReference; 9 | import org.web3j.abi.datatypes.Address; 10 | import org.web3j.abi.datatypes.DynamicArray; 11 | import org.web3j.abi.datatypes.Function; 12 | import org.web3j.abi.datatypes.Type; 13 | import org.web3j.abi.datatypes.Utf8String; 14 | import org.web3j.crypto.Credentials; 15 | import org.web3j.protocol.Web3j; 16 | import org.web3j.protocol.core.RemoteCall; 17 | import org.web3j.protocol.core.methods.response.TransactionReceipt; 18 | import org.web3j.tx.Contract; 19 | import org.web3j.tx.TransactionManager; 20 | 21 | /** 22 | *

Auto generated code. 23 | *

Do not modify! 24 | *

Please use the web3j command line tools, 25 | * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 26 | * codegen module to update. 27 | * 28 | *

Generated with web3j version 3.5.0. 29 | */ 30 | public class AddressBook extends Contract { 31 | private static final String BINARY = "608060405234801561001057600080fd5b50610639806100206000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ba79dfe811461006657806399900d1114610089578063a39fac121461011f578063d033c45614610184575b600080fd5b34801561007257600080fd5b50610087600160a060020a03600435166101eb565b005b34801561009557600080fd5b506100aa600160a060020a0360043516610386565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e45781810151838201526020016100cc565b50505050905090810190601f1680156101115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012b57600080fd5b50610134610438565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610170578181015183820152602001610158565b505050509050019250505060405180910390f35b34801561019057600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610087958335600160a060020a03169536956044949193909101919081908401838280828437509497506104a29650505050505050565b33600090815260208190526040812054905b818110156103815733600090815260208190526040902080548290811061022057fe5b600091825260209091200154600160a060020a03848116911614156103795733600090815260208190526040902054600110801561026057506001820381105b156102e5573360009081526020819052604090208054600019840190811061028457fe5b60009182526020808320909101543383529082905260409091208054600160a060020a0390921691839081106102b657fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b3360009081526020819052604090208054600019840190811061030457fe5b60009182526020808320909101805473ffffffffffffffffffffffffffffffffffffffff191690553382528190526040902080549061034790600019830161050a565b50336000908152600160209081526040808320600160a060020a038716845290915281206103749161052e565b610381565b6001016101fd565b505050565b336000908152600160208181526040808420600160a060020a038616855282529283902080548451600294821615610100026000190190911693909304601f8101839004830284018301909452838352606093909183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b336000908152602081815260409182902080548351818402810184019094528084526060939283018282801561049757602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610479575b505050505090505b90565b3360008181526020818152604080832080546001808201835591855283852001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0389169081179091559484528252808320938352928152919020825161038192840190610575565b815481835581811115610381576000838152602090206103819181019083016105f3565b50805460018160011615610100020316600290046000825580601f106105545750610572565b601f01602090049060005260206000209081019061057291906105f3565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b657805160ff19168380011785556105e3565b828001600101855582156105e3579182015b828111156105e35782518255916020019190600101906105c8565b506105ef9291506105f3565b5090565b61049f91905b808211156105ef57600081556001016105f95600a165627a7a7230582002b4cd1de8dbad4668d406cbb6ac585b72bbd2cfc54d016da10df49ff42ea9e90029"; 32 | 33 | public static final String FUNC_REMOVEADDRESS = "removeAddress"; 34 | 35 | public static final String FUNC_GETALIAS = "getAlias"; 36 | 37 | public static final String FUNC_GETADDRESSES = "getAddresses"; 38 | 39 | public static final String FUNC_ADDADDRESS = "addAddress"; 40 | 41 | protected AddressBook(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 42 | super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); 43 | } 44 | 45 | protected AddressBook(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 46 | super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); 47 | } 48 | 49 | public RemoteCall removeAddress(String addr) { 50 | final Function function = new Function( 51 | FUNC_REMOVEADDRESS, 52 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr)), 53 | Collections.>emptyList()); 54 | return executeRemoteCallTransaction(function); 55 | } 56 | 57 | public RemoteCall getAlias(String addr) { 58 | final Function function = new Function(FUNC_GETALIAS, 59 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr)), 60 | Arrays.>asList(new TypeReference() {})); 61 | return executeRemoteCallSingleValueReturn(function, String.class); 62 | } 63 | 64 | public RemoteCall getAddresses() { 65 | final Function function = new Function(FUNC_GETADDRESSES, 66 | Arrays.asList(), 67 | Arrays.>asList(new TypeReference>() {})); 68 | return new RemoteCall( 69 | new Callable() { 70 | @Override 71 | @SuppressWarnings("unchecked") 72 | public List call() throws Exception { 73 | List result = (List) executeCallSingleValueReturn(function, List.class); 74 | return convertToNative(result); 75 | } 76 | }); 77 | } 78 | 79 | public RemoteCall addAddress(String addr, String alias) { 80 | final Function function = new Function( 81 | FUNC_ADDADDRESS, 82 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr), 83 | new org.web3j.abi.datatypes.Utf8String(alias)), 84 | Collections.>emptyList()); 85 | return executeRemoteCallTransaction(function); 86 | } 87 | 88 | public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 89 | return deployRemoteCall(AddressBook.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); 90 | } 91 | 92 | public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 93 | return deployRemoteCall(AddressBook.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); 94 | } 95 | 96 | public static AddressBook load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 97 | return new AddressBook(contractAddress, web3j, credentials, gasPrice, gasLimit); 98 | } 99 | 100 | public static AddressBook load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 101 | return new AddressBook(contractAddress, web3j, transactionManager, gasPrice, gasLimit); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tutorial-32/src/main/java/youtube/solidity/learning/contracts/AddressBook.java: -------------------------------------------------------------------------------- 1 | package youtube.solidity.learning.contracts; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.concurrent.Callable; 8 | import org.web3j.abi.TypeReference; 9 | import org.web3j.abi.datatypes.Address; 10 | import org.web3j.abi.datatypes.DynamicArray; 11 | import org.web3j.abi.datatypes.Function; 12 | import org.web3j.abi.datatypes.Type; 13 | import org.web3j.abi.datatypes.Utf8String; 14 | import org.web3j.crypto.Credentials; 15 | import org.web3j.protocol.Web3j; 16 | import org.web3j.protocol.core.RemoteCall; 17 | import org.web3j.protocol.core.methods.response.TransactionReceipt; 18 | import org.web3j.tx.Contract; 19 | import org.web3j.tx.TransactionManager; 20 | 21 | /** 22 | *

Auto generated code. 23 | *

Do not modify! 24 | *

Please use the web3j command line tools, 25 | * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 26 | * codegen module to update. 27 | * 28 | *

Generated with web3j version 3.5.0. 29 | */ 30 | public class AddressBook extends Contract { 31 | private static final String BINARY = "608060405234801561001057600080fd5b50610639806100206000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ba79dfe811461006657806399900d1114610089578063a39fac121461011f578063d033c45614610184575b600080fd5b34801561007257600080fd5b50610087600160a060020a03600435166101eb565b005b34801561009557600080fd5b506100aa600160a060020a0360043516610386565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e45781810151838201526020016100cc565b50505050905090810190601f1680156101115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012b57600080fd5b50610134610438565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610170578181015183820152602001610158565b505050509050019250505060405180910390f35b34801561019057600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610087958335600160a060020a03169536956044949193909101919081908401838280828437509497506104a29650505050505050565b33600090815260208190526040812054905b818110156103815733600090815260208190526040902080548290811061022057fe5b600091825260209091200154600160a060020a03848116911614156103795733600090815260208190526040902054600110801561026057506001820381105b156102e5573360009081526020819052604090208054600019840190811061028457fe5b60009182526020808320909101543383529082905260409091208054600160a060020a0390921691839081106102b657fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b3360009081526020819052604090208054600019840190811061030457fe5b60009182526020808320909101805473ffffffffffffffffffffffffffffffffffffffff191690553382528190526040902080549061034790600019830161050a565b50336000908152600160209081526040808320600160a060020a038716845290915281206103749161052e565b610381565b6001016101fd565b505050565b336000908152600160208181526040808420600160a060020a038616855282529283902080548451600294821615610100026000190190911693909304601f8101839004830284018301909452838352606093909183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b336000908152602081815260409182902080548351818402810184019094528084526060939283018282801561049757602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610479575b505050505090505b90565b3360008181526020818152604080832080546001808201835591855283852001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0389169081179091559484528252808320938352928152919020825161038192840190610575565b815481835581811115610381576000838152602090206103819181019083016105f3565b50805460018160011615610100020316600290046000825580601f106105545750610572565b601f01602090049060005260206000209081019061057291906105f3565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b657805160ff19168380011785556105e3565b828001600101855582156105e3579182015b828111156105e35782518255916020019190600101906105c8565b506105ef9291506105f3565b5090565b61049f91905b808211156105ef57600081556001016105f95600a165627a7a7230582002b4cd1de8dbad4668d406cbb6ac585b72bbd2cfc54d016da10df49ff42ea9e90029"; 32 | 33 | public static final String FUNC_REMOVEADDRESS = "removeAddress"; 34 | 35 | public static final String FUNC_GETALIAS = "getAlias"; 36 | 37 | public static final String FUNC_GETADDRESSES = "getAddresses"; 38 | 39 | public static final String FUNC_ADDADDRESS = "addAddress"; 40 | 41 | protected AddressBook(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 42 | super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); 43 | } 44 | 45 | protected AddressBook(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 46 | super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); 47 | } 48 | 49 | public RemoteCall removeAddress(String addr) { 50 | final Function function = new Function( 51 | FUNC_REMOVEADDRESS, 52 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr)), 53 | Collections.>emptyList()); 54 | return executeRemoteCallTransaction(function); 55 | } 56 | 57 | public RemoteCall getAlias(String addr) { 58 | final Function function = new Function(FUNC_GETALIAS, 59 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr)), 60 | Arrays.>asList(new TypeReference() {})); 61 | return executeRemoteCallSingleValueReturn(function, String.class); 62 | } 63 | 64 | public RemoteCall getAddresses() { 65 | final Function function = new Function(FUNC_GETADDRESSES, 66 | Arrays.asList(), 67 | Arrays.>asList(new TypeReference>() {})); 68 | return new RemoteCall( 69 | new Callable() { 70 | @Override 71 | @SuppressWarnings("unchecked") 72 | public List call() throws Exception { 73 | List result = (List) executeCallSingleValueReturn(function, List.class); 74 | return convertToNative(result); 75 | } 76 | }); 77 | } 78 | 79 | public RemoteCall addAddress(String addr, String alias) { 80 | final Function function = new Function( 81 | FUNC_ADDADDRESS, 82 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr), 83 | new org.web3j.abi.datatypes.Utf8String(alias)), 84 | Collections.>emptyList()); 85 | return executeRemoteCallTransaction(function); 86 | } 87 | 88 | public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 89 | return deployRemoteCall(AddressBook.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); 90 | } 91 | 92 | public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 93 | return deployRemoteCall(AddressBook.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); 94 | } 95 | 96 | public static AddressBook load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 97 | return new AddressBook(contractAddress, web3j, credentials, gasPrice, gasLimit); 98 | } 99 | 100 | public static AddressBook load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 101 | return new AddressBook(contractAddress, web3j, transactionManager, gasPrice, gasLimit); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tutorial-33/src/main/java/youtube/solidity/learning/contracts/AddressBook.java: -------------------------------------------------------------------------------- 1 | package youtube.solidity.learning.contracts; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.concurrent.Callable; 8 | import org.web3j.abi.TypeReference; 9 | import org.web3j.abi.datatypes.Address; 10 | import org.web3j.abi.datatypes.DynamicArray; 11 | import org.web3j.abi.datatypes.Function; 12 | import org.web3j.abi.datatypes.Type; 13 | import org.web3j.abi.datatypes.Utf8String; 14 | import org.web3j.crypto.Credentials; 15 | import org.web3j.protocol.Web3j; 16 | import org.web3j.protocol.core.RemoteCall; 17 | import org.web3j.protocol.core.methods.response.TransactionReceipt; 18 | import org.web3j.tx.Contract; 19 | import org.web3j.tx.TransactionManager; 20 | 21 | /** 22 | *

Auto generated code. 23 | *

Do not modify! 24 | *

Please use the web3j command line tools, 25 | * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 26 | * codegen module to update. 27 | * 28 | *

Generated with web3j version 3.5.0. 29 | */ 30 | public class AddressBook extends Contract { 31 | private static final String BINARY = "608060405234801561001057600080fd5b50610639806100206000396000f3006080604052600436106100615763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634ba79dfe811461006657806399900d1114610089578063a39fac121461011f578063d033c45614610184575b600080fd5b34801561007257600080fd5b50610087600160a060020a03600435166101eb565b005b34801561009557600080fd5b506100aa600160a060020a0360043516610386565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100e45781810151838201526020016100cc565b50505050905090810190601f1680156101115780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012b57600080fd5b50610134610438565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610170578181015183820152602001610158565b505050509050019250505060405180910390f35b34801561019057600080fd5b5060408051602060046024803582810135601f8101859004850286018501909652858552610087958335600160a060020a03169536956044949193909101919081908401838280828437509497506104a29650505050505050565b33600090815260208190526040812054905b818110156103815733600090815260208190526040902080548290811061022057fe5b600091825260209091200154600160a060020a03848116911614156103795733600090815260208190526040902054600110801561026057506001820381105b156102e5573360009081526020819052604090208054600019840190811061028457fe5b60009182526020808320909101543383529082905260409091208054600160a060020a0390921691839081106102b657fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b3360009081526020819052604090208054600019840190811061030457fe5b60009182526020808320909101805473ffffffffffffffffffffffffffffffffffffffff191690553382528190526040902080549061034790600019830161050a565b50336000908152600160209081526040808320600160a060020a038716845290915281206103749161052e565b610381565b6001016101fd565b505050565b336000908152600160208181526040808420600160a060020a038616855282529283902080548451600294821615610100026000190190911693909304601f8101839004830284018301909452838352606093909183018282801561042c5780601f106104015761010080835404028352916020019161042c565b820191906000526020600020905b81548152906001019060200180831161040f57829003601f168201915b50505050509050919050565b336000908152602081815260409182902080548351818402810184019094528084526060939283018282801561049757602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610479575b505050505090505b90565b3360008181526020818152604080832080546001808201835591855283852001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0389169081179091559484528252808320938352928152919020825161038192840190610575565b815481835581811115610381576000838152602090206103819181019083016105f3565b50805460018160011615610100020316600290046000825580601f106105545750610572565b601f01602090049060005260206000209081019061057291906105f3565b50565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106105b657805160ff19168380011785556105e3565b828001600101855582156105e3579182015b828111156105e35782518255916020019190600101906105c8565b506105ef9291506105f3565b5090565b61049f91905b808211156105ef57600081556001016105f95600a165627a7a7230582002b4cd1de8dbad4668d406cbb6ac585b72bbd2cfc54d016da10df49ff42ea9e90029"; 32 | 33 | public static final String FUNC_REMOVEADDRESS = "removeAddress"; 34 | 35 | public static final String FUNC_GETALIAS = "getAlias"; 36 | 37 | public static final String FUNC_GETADDRESSES = "getAddresses"; 38 | 39 | public static final String FUNC_ADDADDRESS = "addAddress"; 40 | 41 | protected AddressBook(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 42 | super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); 43 | } 44 | 45 | protected AddressBook(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 46 | super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit); 47 | } 48 | 49 | public RemoteCall removeAddress(String addr) { 50 | final Function function = new Function( 51 | FUNC_REMOVEADDRESS, 52 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr)), 53 | Collections.>emptyList()); 54 | return executeRemoteCallTransaction(function); 55 | } 56 | 57 | public RemoteCall getAlias(String addr) { 58 | final Function function = new Function(FUNC_GETALIAS, 59 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr)), 60 | Arrays.>asList(new TypeReference() {})); 61 | return executeRemoteCallSingleValueReturn(function, String.class); 62 | } 63 | 64 | public RemoteCall getAddresses() { 65 | final Function function = new Function(FUNC_GETADDRESSES, 66 | Arrays.asList(), 67 | Arrays.>asList(new TypeReference>() {})); 68 | return new RemoteCall( 69 | new Callable() { 70 | @Override 71 | @SuppressWarnings("unchecked") 72 | public List call() throws Exception { 73 | List result = (List) executeCallSingleValueReturn(function, List.class); 74 | return convertToNative(result); 75 | } 76 | }); 77 | } 78 | 79 | public RemoteCall addAddress(String addr, String alias) { 80 | final Function function = new Function( 81 | FUNC_ADDADDRESS, 82 | Arrays.asList(new org.web3j.abi.datatypes.Address(addr), 83 | new org.web3j.abi.datatypes.Utf8String(alias)), 84 | Collections.>emptyList()); 85 | return executeRemoteCallTransaction(function); 86 | } 87 | 88 | public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 89 | return deployRemoteCall(AddressBook.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); 90 | } 91 | 92 | public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 93 | return deployRemoteCall(AddressBook.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, ""); 94 | } 95 | 96 | public static AddressBook load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 97 | return new AddressBook(contractAddress, web3j, credentials, gasPrice, gasLimit); 98 | } 99 | 100 | public static AddressBook load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 101 | return new AddressBook(contractAddress, web3j, transactionManager, gasPrice, gasLimit); 102 | } 103 | } 104 | --------------------------------------------------------------------------------