├── .husky ├── pre-commit └── commit-msg ├── basic ├── 13-array │ ├── test │ │ ├── .gitkeep │ │ ├── array_replace_from_end.js │ │ └── array_remove_by_shifting.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ ├── ArrayReplaceFromEnd.sol │ │ └── ArrayRemoveByShifting.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_array_migration.js ├── 14-enum │ ├── test │ │ ├── .gitkeep │ │ ├── TestEnumImport.sol │ │ └── TestEnum.sol │ ├── contracts │ │ ├── .gitkeep │ │ ├── EnumImport.sol │ │ ├── EnumDeclaration.sol │ │ ├── Migrations.sol │ │ └── Enum.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_enum_migration.js ├── 20-error │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Account.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_error_migration.js ├── 32-call │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_call_migration.js ├── 02-first-app │ ├── test │ │ ├── .gitkeep │ │ └── first_app.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── FirstApp.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_first_app_migration.js ├── 04-variables │ ├── test │ │ ├── .gitkeep │ │ └── variables.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Variables.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_variables_migration.js ├── 05-constants │ ├── test │ │ ├── .gitkeep │ │ └── constants.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Constants.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_constants_migration.js ├── 06-immutable │ ├── test │ │ ├── .gitkeep │ │ └── immutable.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Immutable.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_immutable_migration.js ├── 12-mapping │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_mapping_migration.js ├── 15-structs │ ├── test │ │ ├── .gitkeep │ │ ├── TestStructImport.sol │ │ └── TestStructs.sol │ ├── contracts │ │ ├── .gitkeep │ │ ├── StructDeclaration.sol │ │ ├── StructImport.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_structs_migration.js ├── 18-function │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_function_migration.js ├── 22-events │ ├── test │ │ ├── .gitkeep │ │ └── TestEvent.sol │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Event.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_event_migration.js ├── 27-visibility │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_visibility_migration.js ├── 28-interface │ ├── test │ │ ├── .gitkeep │ │ └── TestInterface.sol │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_interface_migration.js ├── 29-payable │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_payable_migration.js ├── 31-fallback │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_fallback_migration.js ├── 37-try-catch │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_try_catch_migration.js ├── 38-import │ ├── test │ │ ├── .gitkeep │ │ └── import.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Foo.sol │ │ ├── Import.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_import_migration.js ├── 39-library │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_library_migration.js ├── 40-abi-encode │ ├── test │ │ ├── .gitkeep │ │ └── abi_encode.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── AbiEncode.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_abi_encode_migration.js ├── 41-abi-decode │ ├── test │ │ ├── .gitkeep │ │ └── abi_decode.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── AbiDecode.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_abi_decode_migration.js ├── 01-hello-world │ ├── test │ │ ├── .gitkeep │ │ └── hello_world.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── HelloWorld.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_hello_world_migration.js ├── 08-ether-and-wei │ ├── test │ │ ├── .gitkeep │ │ └── ether_units.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── EtherUnits.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_ether_units_migration.js ├── 10-if-and-else │ ├── test │ │ ├── .gitkeep │ │ └── if_else.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── IfElse.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 2_if_else_migration.js │ │ └── 1_initial_migration.js ├── 16-data-locations │ ├── test │ │ ├── .gitkeep │ │ └── TestDataLocations.sol │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_data_locations_migration.js ├── 23-constructor │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Constructor.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_constructor_migration.js ├── 24-inheritance │ ├── test │ │ ├── .gitkeep │ │ └── TestInheritance.sol │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_inheritance_migration.js ├── 30-sending-ether │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_sending_ether_migration.js ├── 33-delegatecall │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Delegatecall.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_delegatecall_migration.js ├── 46-unchecked-math │ ├── test │ │ ├── .gitkeep │ │ └── unchecked_math.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── UncheckedMath.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_unchecked_math_migration.js ├── 49-assembly-loop │ ├── test │ │ ├── .gitkeep │ │ └── assembly_loop.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── AssemblyLoop.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_assembly_loop_migration.js ├── 50-assembly-error │ ├── test │ │ ├── .gitkeep │ │ └── assembly_error.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── AssemblyError.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_assembly_error_migration.js ├── 51-assembly-math │ ├── test │ │ ├── .gitkeep │ │ └── assembly_math.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── AssemblyMath.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_assembly_math_migration.js ├── 03-primary-data-types │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_primary_data_types_migration.js ├── 09-gas-and-gas-price │ ├── test │ │ ├── .gitkeep │ │ └── gas.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Gas.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 2_gas_migration.js │ │ └── 1_initial_migration.js ├── 11-for-and-while-loop │ ├── test │ │ ├── .gitkeep │ │ └── loop.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── Loop.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 2_loop_migration.js │ │ └── 1_initial_migration.js ├── 17-transient-storage │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_transient_storage_migration.js ├── 21-function-modifier │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_function_modifier_migration.js ├── 34-function-selector │ ├── test │ │ ├── .gitkeep │ │ └── function_selector.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── FunctionSelector.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_function_selector_migration.js ├── 43-verifying-signature │ ├── test │ │ ├── .gitkeep │ │ └── verify_signature.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_verify_signature_migration.js ├── 45-bitwise-operators │ ├── test │ │ ├── .gitkeep │ │ ├── most_significant_bit_assembly.js │ │ └── most_significant_bit_function.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── MostSignificantBitFunction .sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ ├── 2_bitwise_ops_migration.js │ │ ├── 3_most_significant_bit_function.js │ │ └── 4_most_significant_bit_assembly.js ├── 47-assembly-variable │ ├── test │ │ ├── .gitkeep │ │ └── assembly_variable.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── AssemblyVariable.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_assembly_variable_migration.js ├── 19-view-and-pure-functions │ ├── test │ │ ├── .gitkeep │ │ └── TestViewAndPure.sol │ ├── contracts │ │ ├── .gitkeep │ │ ├── ViewAndPure.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_view_and_pure_migration.js ├── 26-calling-parent-contracts │ ├── test │ │ ├── .gitkeep │ │ └── TestCallingParentContracts.sol │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_calling_parent_contracts_migration.js ├── 35-calling-other-contract │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── CallingOtherContract.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_calling_other_contract_migration.js ├── 42-hashing-with-keccak256 │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_hash_with_keccak256_migration.js ├── 44-gas-saving-techniques │ ├── test │ │ ├── .gitkeep │ │ └── gas_golf.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_gas_golf_migration.js ├── 25-shadowing-inherited-state-variables │ ├── test │ │ ├── .gitkeep │ │ └── TestShadowingInherits.sol │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── ShadowingInherits.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_shadowing_inherits_migration.js ├── 48-assembly-conditional-statements │ ├── test │ │ ├── .gitkeep │ │ └── assembly_if.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── Migrations.sol │ │ └── AssemblyIf.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_assembly_if_migration.js ├── 07-reading-and-writing-to-a-state-variable │ ├── test │ │ ├── .gitkeep │ │ └── simple_storage.js │ ├── contracts │ │ ├── .gitkeep │ │ ├── SimpleStorage.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_simple_storage_migration.js └── 36-contract-that-creates-other-contracts │ ├── test │ └── .gitkeep │ ├── contracts │ ├── .gitkeep │ └── Migrations.sol │ └── migrations │ ├── .gitkeep │ ├── 1_initial_migration.js │ └── 2_car_factory_migration.js ├── applications ├── 05-erc20 │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ ├── MyToken.sol │ │ ├── IERC20.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ └── 1_initial_migration.js ├── 06-erc721 │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ └── 1_initial_migration.js ├── 07-erc1155 │ ├── test │ │ ├── .gitkeep │ │ └── my_multi_token.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_my_multi_token_migration.js ├── 01-ether-wallet │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ ├── EtherWallet.sol │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_ether_wallet_migration.js ├── 03-merkle-tree │ ├── test │ │ ├── .gitkeep │ │ └── test_merkel_proof.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_merkle_proof_migration.js ├── 02-multi-sig-wallet │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ └── 1_initial_migration.js ├── 04-iterable-mapping │ ├── test │ │ ├── .gitkeep │ │ └── iterable_mapping.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_iterable_mapping_migration.js ├── 12-upgradeable-proxy │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_upgradeable_proxy_migration.js ├── 08-gasless-token-transfer │ ├── test │ │ ├── .gitkeep │ │ └── erc20_permit.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_gasless_token_transfer_migration.js ├── 11-minimal-proxy-contract │ ├── test │ │ ├── .gitkeep │ │ └── minimal_proxy.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_minimal_proxy_migration.js ├── 13-deploy-any-contract │ ├── test │ │ └── .gitkeep │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_proxy_migration.js ├── 09-simple-bytecode-contract │ ├── test │ │ ├── .gitkeep │ │ └── factory.js │ ├── contracts │ │ ├── .gitkeep │ │ └── Migrations.sol │ └── migrations │ │ ├── .gitkeep │ │ ├── 1_initial_migration.js │ │ └── 2_factory_migration.js └── 10-precompute-contract-address-width-create2 │ ├── test │ ├── .gitkeep │ └── create2.js │ ├── contracts │ ├── .gitkeep │ └── Migrations.sol │ └── migrations │ ├── .gitkeep │ ├── 2_create2_migration.js │ └── 1_initial_migration.js ├── .github ├── CODEOWNERS └── workflows │ ├── proof-html.yml │ └── auto-assign.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── commitlint.config.js ├── .vscode └── settings.json ├── LICENSE └── package.json /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/13-array/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/14-enum/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/20-error/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/32-call/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/02-first-app/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/04-variables/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/05-constants/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/06-immutable/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/12-mapping/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/13-array/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/14-enum/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/14-enum/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/15-structs/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/18-function/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/20-error/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/22-events/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/27-visibility/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/28-interface/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/29-payable/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/31-fallback/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/32-call/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/32-call/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/37-try-catch/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/38-import/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/39-library/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/40-abi-encode/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/41-abi-decode/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/05-erc20/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/06-erc721/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/07-erc1155/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/01-hello-world/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/02-first-app/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/02-first-app/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/04-variables/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/04-variables/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/05-constants/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/05-constants/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/06-immutable/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/06-immutable/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/10-if-and-else/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/12-mapping/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/12-mapping/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/13-array/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/15-structs/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/15-structs/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/16-data-locations/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/18-function/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/18-function/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/20-error/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/22-events/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/22-events/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/23-constructor/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/24-inheritance/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/27-visibility/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/28-interface/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/28-interface/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/29-payable/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/29-payable/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/30-sending-ether/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/31-fallback/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/31-fallback/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/33-delegatecall/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/37-try-catch/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/37-try-catch/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/38-import/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/38-import/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/39-library/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/39-library/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/40-abi-encode/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/41-abi-decode/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/50-assembly-error/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/51-assembly-math/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @james-gates-0212 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | pnpm commitlint ${1} 2 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/05-erc20/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/05-erc20/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/06-erc721/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/06-erc721/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/07-erc1155/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/07-erc1155/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/01-hello-world/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/01-hello-world/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/03-primary-data-types/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/10-if-and-else/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/10-if-and-else/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/16-data-locations/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/16-data-locations/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/17-transient-storage/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/21-function-modifier/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/23-constructor/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/23-constructor/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/24-inheritance/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/24-inheritance/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/27-visibility/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/30-sending-ether/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/30-sending-ether/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/33-delegatecall/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/33-delegatecall/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/34-function-selector/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/40-abi-encode/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/41-abi-decode/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/50-assembly-error/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/50-assembly-error/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/51-assembly-math/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/51-assembly-math/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/02-multi-sig-wallet/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/12-upgradeable-proxy/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/03-primary-data-types/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/03-primary-data-types/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/17-transient-storage/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/17-transient-storage/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/21-function-modifier/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/21-function-modifier/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/34-function-selector/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/34-function-selector/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/42-hashing-with-keccak256/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/02-multi-sig-wallet/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/02-multi-sig-wallet/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/12-upgradeable-proxy/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/12-upgradeable-proxy/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/13-deploy-any-contract/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/42-hashing-with-keccak256/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/42-hashing-with-keccak256/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/13-deploy-any-contract/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/13-deploy-any-contract/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/36-contract-that-creates-other-contracts/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/36-contract-that-creates-other-contracts/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/36-contract-that-creates-other-contracts/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/contracts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /basic/14-enum/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/32-call/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/02-first-app/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/02-first-app/migrations/2_first_app_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('FirstApp'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/04-variables/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/05-constants/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/06-immutable/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/migrations/2_gas_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Gas'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/10-if-and-else/migrations/2_if_else_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('IfElse'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/migrations/2_loop_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Loop'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/12-mapping/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/13-array/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/15-structs/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/18-function/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/20-error/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/22-events/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/22-events/migrations/2_event_migration.js: -------------------------------------------------------------------------------- 1 | const EventContract = artifacts.require('Event'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(EventContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/28-interface/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/29-payable/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/31-fallback/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/37-try-catch/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/38-import/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/38-import/migrations/2_import_migration.js: -------------------------------------------------------------------------------- 1 | const ImportContract = artifacts.require('Import'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(ImportContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/39-library/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/05-erc20/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/06-erc721/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/07-erc1155/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/01-hello-world/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/04-variables/migrations/2_variables_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Variables'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/05-constants/migrations/2_constants_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Constants'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/10-if-and-else/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/16-data-locations/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/23-constructor/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/24-inheritance/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/27-visibility/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/29-payable/migrations/2_payable_migration.js: -------------------------------------------------------------------------------- 1 | const PayableContract = artifacts.require('Payable'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(PayableContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/30-sending-ether/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/33-delegatecall/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/40-abi-encode/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/41-abi-decode/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/50-assembly-error/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/51-assembly-math/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # npm packages 2 | node_modules 3 | 4 | # truffle 5 | build 6 | 7 | # typechain 8 | types 9 | 10 | # buidler 11 | artifacts 12 | cache 13 | 14 | # compiled solidity 15 | *.bin 16 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/01-hello-world/migrations/2_hello_world_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('HelloWorld'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/03-primary-data-types/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/06-immutable/migrations/2_immutable_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Immutable'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations, 123); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/migrations/2_ether_units_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('EtherUnits'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/17-transient-storage/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/21-function-modifier/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/34-function-selector/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/02-multi-sig-wallet/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/12-upgradeable-proxy/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/14-enum/contracts/EnumImport.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | import "./EnumDeclaration.sol"; 5 | 6 | contract EnumImport { 7 | Status public status; 8 | } 9 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/42-hashing-with-keccak256/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/13-deploy-any-contract/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/40-abi-encode/migrations/2_abi_encode_migration.js: -------------------------------------------------------------------------------- 1 | const AbiEncodeContract = artifacts.require('AbiEncode'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AbiEncodeContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/41-abi-decode/migrations/2_abi_decode_migration.js: -------------------------------------------------------------------------------- 1 | const AbiDecodeContract = artifacts.require('AbiDecode'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AbiDecodeContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/migrations/2_gas_golf_migration.js: -------------------------------------------------------------------------------- 1 | const GasGolfContract = artifacts.require('GasGolf'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(GasGolfContract); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/16-data-locations/migrations/2_data_locations_migration.js: -------------------------------------------------------------------------------- 1 | const DataLocations = artifacts.require('DataLocations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(DataLocations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/migrations/2_factory_migration.js: -------------------------------------------------------------------------------- 1 | const FactoryContract = artifacts.require('Factory'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(FactoryContract); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/migrations/2_create2_migration.js: -------------------------------------------------------------------------------- 1 | const Factory = artifacts.require('Factory'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Factory); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/03-primary-data-types/migrations/2_primary_data_types_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('PrimaryDataTypes'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/17-transient-storage/migrations/2_transient_storage_migration.js: -------------------------------------------------------------------------------- 1 | const CallbackContract = artifacts.require('Callback'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(CallbackContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/36-contract-that-creates-other-contracts/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/migrations/2_bitwise_ops_migration.js: -------------------------------------------------------------------------------- 1 | const BitwiseOpsContract = artifacts.require('BitwiseOps'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(BitwiseOpsContract); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/migrations/2_ether_wallet_migration.js: -------------------------------------------------------------------------------- 1 | const EtherWalletContract = artifacts.require('EtherWallet'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(EtherWalletContract); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/07-erc1155/migrations/2_my_multi_token_migration.js: -------------------------------------------------------------------------------- 1 | const MyMultiTokenContract = artifacts.require('MyMultiToken'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(MyMultiTokenContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/migrations/2_assembly_loop_migration.js: -------------------------------------------------------------------------------- 1 | const AssemblyLoopContract = artifacts.require('AssemblyLoop'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AssemblyLoopContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/51-assembly-math/migrations/2_assembly_math_migration.js: -------------------------------------------------------------------------------- 1 | const AssemblyMathContract = artifacts.require('AssemblyMath'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AssemblyMathContract); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/migrations/2_simple_storage_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('SimpleStorage'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/15-structs/contracts/StructDeclaration.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | struct Todo { 5 | string text; 6 | bool completed; 7 | } 8 | 9 | contract StructDeclaration {} 10 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/migrations/2_view_and_pure_migration.js: -------------------------------------------------------------------------------- 1 | const ViewAndPureContract = artifacts.require('ViewAndPure'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(ViewAndPureContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/migrations/2_unchecked_math_migration.js: -------------------------------------------------------------------------------- 1 | const UncheckedMathContract = artifacts.require('UncheckedMath'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(UncheckedMathContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/50-assembly-error/migrations/2_assembly_error_migration.js: -------------------------------------------------------------------------------- 1 | const AssemblyErrorContract = artifacts.require('AssemblyError'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AssemblyErrorContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/migrations/2_assembly_if_migration.js: -------------------------------------------------------------------------------- 1 | const AssemblyIfContract = artifacts.require('AssemblyIf'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AssemblyIfContract); 5 | }; 6 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/migrations/2_minimal_proxy_migration.js: -------------------------------------------------------------------------------- 1 | const MinimalProxyContract = artifacts.require('MinimalProxy'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(MinimalProxyContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/36-contract-that-creates-other-contracts/migrations/2_car_factory_migration.js: -------------------------------------------------------------------------------- 1 | const CarFactoryContract = artifacts.require('CarFactory'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(CarFactoryContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/migrations/2_verify_signature_migration.js: -------------------------------------------------------------------------------- 1 | const VerifySignatureContract = artifacts.require('VerifySignature'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(VerifySignatureContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/21-function-modifier/migrations/2_function_modifier_migration.js: -------------------------------------------------------------------------------- 1 | const FunctionModifierContract = artifacts.require('FunctionModifier'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(FunctionModifierContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/34-function-selector/migrations/2_function_selector_migration.js: -------------------------------------------------------------------------------- 1 | const FunctionSelectorContract = artifacts.require('FunctionSelector'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(FunctionSelectorContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/migrations/2_assembly_variable_migration.js: -------------------------------------------------------------------------------- 1 | const AssemblyVariableContract = artifacts.require('AssemblyVariable'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(AssemblyVariableContract); 5 | }; 6 | -------------------------------------------------------------------------------- /.github/workflows/proof-html.yml: -------------------------------------------------------------------------------- 1 | name: Proof HTML 2 | on: 3 | push: 4 | workflow_dispatch: 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: anishathalye/proof-html@v1.1.0 10 | with: 11 | directory: ./ 12 | -------------------------------------------------------------------------------- /basic/14-enum/contracts/EnumDeclaration.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | enum Status { 5 | Pending, 6 | Shipped, 7 | Accepted, 8 | Rejected, 9 | Canceled 10 | } 11 | 12 | contract EnumDeclaration {} 13 | -------------------------------------------------------------------------------- /basic/33-delegatecall/migrations/2_delegatecall_migration.js: -------------------------------------------------------------------------------- 1 | const AContract = artifacts.require('A'); 2 | const BContract = artifacts.require('B'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(AContract); 6 | deployer.deploy(BContract); 7 | }; 8 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/migrations/2_gasless_token_transfer_migration.js: -------------------------------------------------------------------------------- 1 | const GaslessTokenTransferContract = artifacts.require('GaslessTokenTransfer'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(GaslessTokenTransferContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/migrations/3_most_significant_bit_function.js: -------------------------------------------------------------------------------- 1 | const MostSignificantBitFunctionContract = artifacts.require('MostSignificantBitFunction'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(MostSignificantBitFunctionContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/migrations/4_most_significant_bit_assembly.js: -------------------------------------------------------------------------------- 1 | const MostSignificantBitAssemblyContract = artifacts.require('MostSignificantBitAssembly'); 2 | 3 | module.exports = function (deployer) { 4 | deployer.deploy(MostSignificantBitAssemblyContract); 5 | }; 6 | -------------------------------------------------------------------------------- /basic/20-error/migrations/2_error_migration.js: -------------------------------------------------------------------------------- 1 | const ErrorContract = artifacts.require('Error'); 2 | const AccountContract = artifacts.require('Account'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(ErrorContract); 6 | deployer.deploy(AccountContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/27-visibility/migrations/2_visibility_migration.js: -------------------------------------------------------------------------------- 1 | const BaseContract = artifacts.require('Base'); 2 | const ChildContract = artifacts.require('Child'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(BaseContract); 6 | deployer.deploy(ChildContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/18-function/migrations/2_function_migration.js: -------------------------------------------------------------------------------- 1 | const FunctionContract = artifacts.require('Function'); 2 | const XYZContract = artifacts.require('XYZ'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(FunctionContract); 6 | deployer.deploy(XYZContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/32-call/migrations/2_call_migration.js: -------------------------------------------------------------------------------- 1 | const ReceiverContract = artifacts.require('Receiver'); 2 | const CallerContract = artifacts.require('Caller'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(ReceiverContract); 6 | deployer.deploy(CallerContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/14-enum/migrations/2_enum_migration.js: -------------------------------------------------------------------------------- 1 | const EnumMigration = artifacts.require('Enum'); 2 | const EnumImportMigration = artifacts.require('EnumImport'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(EnumMigration); 6 | deployer.deploy(EnumImportMigration); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/15-structs/migrations/2_structs_migration.js: -------------------------------------------------------------------------------- 1 | const TodosContract = artifacts.require('Todos'); 2 | const TodosImportContract = artifacts.require('TodosImport'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(TodosContract); 6 | deployer.deploy(TodosImportContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/migrations/2_shadowing_inherits_migration.js: -------------------------------------------------------------------------------- 1 | const AContract = artifacts.require('A'); 2 | const CContract = artifacts.require('C'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(AContract); 6 | deployer.deploy(CContract); 7 | }; 8 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Ignore artifacts 2 | .DS_Store 3 | .env 4 | .gitignore 5 | .next 6 | .prettierignore 7 | build 8 | dist 9 | node_modules 10 | pnpm-lock.yaml 11 | 12 | # Ignore files 13 | *.gif 14 | *.ico 15 | *.jpeg 16 | *.jpg 17 | *.lock 18 | *.png 19 | *.svg 20 | *.txt 21 | *.woff 22 | *.woff2 23 | -------------------------------------------------------------------------------- /basic/12-mapping/migrations/2_mapping_migration.js: -------------------------------------------------------------------------------- 1 | const MappingMigration = artifacts.require('Mapping'); 2 | const NestedMappingMigration = artifacts.require('NestedMapping'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(MappingMigration); 6 | deployer.deploy(NestedMappingMigration); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/migrations/2_calling_other_contract_migration.js: -------------------------------------------------------------------------------- 1 | const CalleeContract = artifacts.require('Callee'); 2 | const CallerContract = artifacts.require('Caller'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(CalleeContract); 6 | deployer.deploy(CallerContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/37-try-catch/migrations/2_try_catch_migration.js: -------------------------------------------------------------------------------- 1 | const BarContract = artifacts.require('Bar'); 2 | // const FooContract = artifacts.require('Foo'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(BarContract); 6 | // deployer.deploy(FooContract, 0x0000000000000000000000000000000000000000); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/30-sending-ether/migrations/2_sending_ether_migration.js: -------------------------------------------------------------------------------- 1 | const ReceiveEtherContract = artifacts.require('ReceiveEther'); 2 | const SendEtherContract = artifacts.require('SendEther'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(ReceiveEtherContract); 6 | deployer.deploy(SendEtherContract); 7 | }; 8 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/migrations/2_merkle_proof_migration.js: -------------------------------------------------------------------------------- 1 | const MerkleProofContract = artifacts.require('MerkleProof'); 2 | const TestMerkleProofContract = artifacts.require('TestMerkleProof'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(MerkleProofContract); 6 | deployer.deploy(TestMerkleProofContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/42-hashing-with-keccak256/migrations/2_hash_with_keccak256_migration.js: -------------------------------------------------------------------------------- 1 | const HashFunctionContract = artifacts.require('HashFunction'); 2 | const GuessTheMagicWordContract = artifacts.require('GuessTheMagicWord'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(HashFunctionContract); 6 | deployer.deploy(GuessTheMagicWordContract); 7 | }; 8 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/test/loop.js: -------------------------------------------------------------------------------- 1 | const LoopContract = artifacts.require('Loop'); 2 | 3 | contract('Loop', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await LoopContract.deployed(); 8 | }); 9 | 10 | it('for and while loop', async () => { 11 | await contractInstance.loop(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /basic/38-import/contracts/Foo.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | struct Point { 5 | uint256 x; 6 | uint256 y; 7 | } 8 | 9 | error Unauthorized(address caller); 10 | 11 | function add(uint256 x, uint256 y) pure returns (uint256) { 12 | return x + y; 13 | } 14 | 15 | contract Foo { 16 | string public name = "Foo"; 17 | } 18 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/contracts/AssemblyVariable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract AssemblyVariable { 5 | function yul_let() public pure returns (uint256 z) { 6 | assembly { 7 | // Language used for assembly is called Yul 8 | // Local variables 9 | let x := 123 10 | z := 456 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /basic/28-interface/migrations/2_interface_migration.js: -------------------------------------------------------------------------------- 1 | const CounterContract = artifacts.require('Counter'); 2 | const MyContractContract = artifacts.require('MyContract'); 3 | const UniswapExampleContract = artifacts.require('UniswapExample'); 4 | 5 | module.exports = function (deployer) { 6 | deployer.deploy(CounterContract); 7 | deployer.deploy(MyContractContract); 8 | deployer.deploy(UniswapExampleContract); 9 | }; 10 | -------------------------------------------------------------------------------- /basic/13-array/test/array_replace_from_end.js: -------------------------------------------------------------------------------- 1 | const ArrayReplaceFromEnd = artifacts.require('ArrayReplaceFromEnd'); 2 | 3 | contract('ArrayReplaceFromEnd', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await ArrayReplaceFromEnd.new(); 8 | }); 9 | 10 | it('should remove elements from the array', async () => { 11 | await contractInstance.test(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/test/iterable_mapping.js: -------------------------------------------------------------------------------- 1 | const TestIterableMap = artifacts.require('TestIterableMap'); 2 | 3 | contract('TestIterableMap', (accounts) => { 4 | it('should test the iterable map', async () => { 5 | const contractInstance = await TestIterableMap.deployed(); 6 | 7 | await contractInstance.testIterableMap(); 8 | 9 | // Assert any additional conditions or validations here 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/migrations/2_iterable_mapping_migration.js: -------------------------------------------------------------------------------- 1 | const IterableMappingContract = artifacts.require('IterableMapping'); 2 | const TestIterableMappingContract = artifacts.require('TestIterableMap'); 3 | 4 | module.exports = function (deployer) { 5 | deployer.deploy(IterableMappingContract); 6 | deployer.link(IterableMappingContract, TestIterableMappingContract); 7 | deployer.deploy(TestIterableMappingContract); 8 | }; 9 | -------------------------------------------------------------------------------- /basic/13-array/test/array_remove_by_shifting.js: -------------------------------------------------------------------------------- 1 | const ArrayRemoveByShifting = artifacts.require('ArrayRemoveByShifting'); 2 | 3 | contract('ArrayRemoveByShifting', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await ArrayRemoveByShifting.new(); 8 | }); 9 | 10 | it('should remove elements from the array', async () => { 11 | await contractInstance.test(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /basic/15-structs/contracts/StructImport.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | import "./StructDeclaration.sol"; 5 | 6 | contract TodosImport { 7 | // An array of 'Todo' structs 8 | Todo[] public todos; 9 | 10 | function push(Todo memory todo) public { 11 | todos.push(todo); 12 | } 13 | 14 | function get() public view returns (Todo[] memory) { 15 | return todos; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /basic/22-events/test/TestEvent.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../contracts/Event.sol"; 5 | 6 | contract TestEvent { 7 | Event public eventContract; 8 | 9 | function beforeEach() public { 10 | eventContract = new Event(); 11 | } 12 | 13 | function testEvent() public { 14 | // Call the test function that emits the event 15 | eventContract.test(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/migrations/2_calling_parent_contracts_migration.js: -------------------------------------------------------------------------------- 1 | const AContract = artifacts.require('A'); 2 | const BContract = artifacts.require('B'); 3 | const CContract = artifacts.require('C'); 4 | const DContract = artifacts.require('D'); 5 | 6 | module.exports = function (deployer) { 7 | deployer.deploy(AContract); 8 | deployer.deploy(BContract); 9 | deployer.deploy(CContract); 10 | deployer.deploy(DContract); 11 | }; 12 | -------------------------------------------------------------------------------- /basic/05-constants/contracts/Constants.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // Constants are variables that cannot be modified. 5 | // Their value is hard coded and using constants can save gas cost. 6 | contract Constants { 7 | // coding convention to uppercase constant variables 8 | address public constant MY_ADDRESS = 0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc; 9 | uint256 public constant MY_UINT = 123; 10 | } 11 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/test/gas.js: -------------------------------------------------------------------------------- 1 | const GasContract = artifacts.require('Gas'); 2 | 3 | contract('Gas', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await GasContract.deployed(); 8 | }); 9 | 10 | it('looping 1000 times', async () => { 11 | await contractInstance.looping(1000); 12 | 13 | const value = await contractInstance.i(); 14 | 15 | assert.equal(value, 1000); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /basic/13-array/migrations/2_array_migration.js: -------------------------------------------------------------------------------- 1 | const ArrayMigration = artifacts.require('Array'); 2 | const ArrayRemoveByShiftingMigration = artifacts.require('ArrayRemoveByShifting'); 3 | const ArrayReplaceFromEndMigration = artifacts.require('ArrayReplaceFromEnd'); 4 | 5 | module.exports = function (deployer) { 6 | deployer.deploy(ArrayMigration); 7 | deployer.deploy(ArrayRemoveByShiftingMigration); 8 | deployer.deploy(ArrayReplaceFromEndMigration); 9 | }; 10 | -------------------------------------------------------------------------------- /basic/01-hello-world/contracts/HelloWorld.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract HelloWorld { 5 | string message; 6 | 7 | constructor() { 8 | message = "Hello, World!"; 9 | } 10 | 11 | function setMessage(string memory new_message) public { 12 | message = new_message; 13 | } 14 | 15 | function getMessage() public view returns (string memory) { 16 | return message; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /applications/13-deploy-any-contract/migrations/2_proxy_migration.js: -------------------------------------------------------------------------------- 1 | const Proxy = artifacts.require('Proxy'); 2 | const TestContract1 = artifacts.require('TestContract1'); 3 | const TestContract2 = artifacts.require('TestContract2'); 4 | const Helper = artifacts.require('Helper'); 5 | 6 | module.exports = function (deployer) { 7 | deployer.deploy(Proxy); 8 | deployer.deploy(TestContract1); 9 | deployer.deploy(TestContract2, 10, 20); 10 | deployer.deploy(Helper); 11 | }; 12 | -------------------------------------------------------------------------------- /basic/50-assembly-error/contracts/AssemblyError.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract AssemblyError { 5 | function yul_revert(uint256 x) public pure { 6 | assembly { 7 | // revert(p, s) - end execution 8 | // revert state changes 9 | // return data mem[p…(p+s)) 10 | if gt(x, 10) { 11 | revert(0, 0) 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /basic/24-inheritance/migrations/2_inheritance_migration.js: -------------------------------------------------------------------------------- 1 | const AContract = artifacts.require('A'); 2 | const BContract = artifacts.require('B'); 3 | const CContract = artifacts.require('C'); 4 | const DContract = artifacts.require('D'); 5 | const EContract = artifacts.require('E'); 6 | 7 | module.exports = function (deployer) { 8 | deployer.deploy(AContract); 9 | deployer.deploy(BContract); 10 | deployer.deploy(CContract); 11 | deployer.deploy(DContract); 12 | deployer.deploy(EContract); 13 | }; 14 | -------------------------------------------------------------------------------- /.github/workflows/auto-assign.yml: -------------------------------------------------------------------------------- 1 | name: Auto Assign 2 | on: 3 | issues: 4 | types: [opened] 5 | pull_request: 6 | types: [opened] 7 | jobs: 8 | run: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | steps: 14 | - name: 'Auto-assign issue' 15 | uses: pozil/auto-assign-issue@v1 16 | with: 17 | repo-token: ${{ secrets.GITHUB_TOKEN }} 18 | assignees: james-gates-0212 19 | numOfAssignee: 1 20 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "printWidth": 120, 4 | "singleQuote": true, 5 | "tabWidth": 2, 6 | "trailingComma": "all", 7 | "plugins": ["prettier-plugin-solidity"], 8 | "overrides": [ 9 | { 10 | "files": "*.sol", 11 | "options": { 12 | "parser": "solidity-parse", 13 | "bracketSpacing": false, 14 | "printWidth": 120, 15 | "singleQuote": false, 16 | "tabWidth": 4, 17 | "useTabs": false 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /applications/05-erc20/contracts/MyToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | import "./ERC20.sol"; 5 | 6 | contract MyToken is ERC20 { 7 | constructor(string memory name, string memory symbol, uint8 decimals) ERC20(name, symbol, decimals) { 8 | // Mint 100 tokens to msg.sender 9 | // Similar to how 10 | // 1 dollar = 100 cents 11 | // 1 token = 1 * (10 ** decimals) 12 | _mint(msg.sender, 100 * 10 ** uint256(decimals)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/test/TestCallingParentContracts.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../contracts/CallingParentContracts.sol"; 5 | 6 | contract TestCallingParentContracts { 7 | D public contractInstance; 8 | 9 | function beforeEach() public { 10 | contractInstance = new D(); 11 | } 12 | 13 | function testCallingParentContracts() public { 14 | contractInstance.foo(); 15 | contractInstance.bar(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/contracts/EtherUnits.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // Transactions are paid with ether. 5 | // Similar to how one dollar is equal to 100 cents, one ether is equal to 10 ** 18 wei. 6 | contract EtherUnits { 7 | uint256 public oneWei = 1 wei; 8 | // 1 wei is equal to 1 9 | bool public isOneWei = 1 wei == 1; 10 | 11 | uint256 public oneEther = 1 ether; 12 | // 1 ether is equal to 10^18 wei 13 | bool public isOneEther = 1 ether == 1e18; 14 | } 15 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/test/TestShadowingInherits.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "truffle/Assert.sol"; 5 | import "../contracts/ShadowingInherits.sol"; 6 | 7 | contract InheritanceTest { 8 | C public c; 9 | 10 | function beforeEach() public { 11 | c = new C(); 12 | } 13 | 14 | function testC() public { 15 | string memory expected = "Contract C"; 16 | 17 | Assert.equal(c.getName(), expected, "Incorrect name in contract C"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /basic/06-immutable/contracts/Immutable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // Immutable variables are like constants. 5 | // Values of immutable variables can be set inside the constructor but cannot be modified afterwards. 6 | contract Immutable { 7 | // coding convention to uppercase constant variables 8 | address public immutable MY_ADDRESS; 9 | uint256 public immutable MY_UINT; 10 | 11 | constructor(uint256 _myUint) { 12 | MY_ADDRESS = msg.sender; 13 | MY_UINT = _myUint; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /basic/38-import/contracts/Import.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // import Foo.sol from current directory 5 | import "./Foo.sol"; 6 | 7 | // import {symbol1 as alias, symbol2} from "filename"; 8 | import {Unauthorized, add as func, Point} from "./Foo.sol"; 9 | 10 | contract Import { 11 | // Initialize Foo.sol 12 | Foo public foo = new Foo(); 13 | 14 | // Test Foo.sol by getting it's name. 15 | function getFooName() public view returns (string memory) { 16 | return foo.name(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /basic/39-library/migrations/2_library_migration.js: -------------------------------------------------------------------------------- 1 | const MathLibrary = artifacts.require('Math'); 2 | const TestMathContract = artifacts.require('TestMath'); 3 | const ArrayLibrary = artifacts.require('Array'); 4 | const TestArrayContract = artifacts.require('TestArray'); 5 | 6 | module.exports = function (deployer) { 7 | deployer.deploy(MathLibrary); 8 | deployer.link(MathLibrary, TestMathContract); 9 | deployer.deploy(TestMathContract); 10 | deployer.deploy(ArrayLibrary); 11 | deployer.link(ArrayLibrary, TestArrayContract); 12 | deployer.deploy(TestArrayContract); 13 | }; 14 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | const config = { 2 | extends: ['gitmoji'], 3 | rules: { 4 | 'type-enum': [ 5 | 2, 6 | 'always', 7 | [ 8 | 'add', 9 | 'adopt', 10 | 'apply', 11 | 'build', 12 | 'chore', 13 | 'config', 14 | 'delete', 15 | 'docs', 16 | 'feat', 17 | 'fix', 18 | 'init', 19 | 'refactor', 20 | 'remove', 21 | 'style', 22 | 'test', 23 | 'update', 24 | 'upgrade', 25 | ], 26 | ], 27 | }, 28 | }; 29 | 30 | module.exports = config; 31 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/test/simple_storage.js: -------------------------------------------------------------------------------- 1 | const SimpleStorageContract = artifacts.require('SimpleStorage'); 2 | 3 | contract('Simple Storage', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await SimpleStorageContract.deployed(); 8 | }); 9 | 10 | it('writing to a state variable', async () => { 11 | await contractInstance.set(123); 12 | }); 13 | 14 | it('reading from a state variable', async () => { 15 | const value = await contractInstance.get(); 16 | 17 | assert.equal(value, 123); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /basic/14-enum/test/TestEnumImport.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../contracts/EnumImport.sol"; 5 | import "../contracts/EnumDeclaration.sol"; 6 | 7 | contract TestEnumImport { 8 | EnumImport public enumImportContract; 9 | 10 | function beforeEach() public { 11 | enumImportContract = new EnumImport(); 12 | } 13 | 14 | function testEnumImport() external { 15 | // Initial status should be "Pending" 16 | Status initialStatus = enumImportContract.status(); 17 | assert(initialStatus == Status.Pending); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/test/gas_golf.js: -------------------------------------------------------------------------------- 1 | const GasGolf = artifacts.require('GasGolf'); 2 | 3 | contract('GasGolf', (accounts) => { 4 | it('should calculate the sum correctly', async () => { 5 | const gasGolf = await GasGolf.deployed(); 6 | const nums = [1, 2, 3, 4, 5, 100]; 7 | const expectedTotal = nums.filter((num) => num % 2 === 0 && num < 99).reduce((acc, num) => acc + num, 0); 8 | 9 | await gasGolf.sumIfEvenAndLessThan99(nums); 10 | const total = await gasGolf.total(); 11 | 12 | assert.equal(total.toNumber(), expectedTotal, 'The calculated total is incorrect'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/contracts/EtherWallet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract EtherWallet { 5 | address payable public owner; 6 | 7 | constructor() { 8 | owner = payable(msg.sender); 9 | } 10 | 11 | receive() external payable {} 12 | 13 | function withdraw(uint256 _amount) external { 14 | require(msg.sender == owner, "caller is not owner"); 15 | payable(msg.sender).transfer(_amount); 16 | } 17 | 18 | function getBalance() external view returns (uint256) { 19 | return address(this).balance; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/06-immutable/test/immutable.js: -------------------------------------------------------------------------------- 1 | const ImmutableContract = artifacts.require('Immutable'); 2 | 3 | contract('Immutable', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await ImmutableContract.deployed(); 8 | }); 9 | 10 | it(`should display ${accounts[0]}`, async function () { 11 | const myAddress = await contractInstance.MY_ADDRESS(); 12 | assert.equal(myAddress, accounts[0]); 13 | }); 14 | 15 | it('should display 123', async function () { 16 | const myUint = await contractInstance.MY_UINT(); 17 | assert.equal(myUint, 123); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /basic/23-constructor/migrations/2_constructor_migration.js: -------------------------------------------------------------------------------- 1 | const XContract = artifacts.require('X'); 2 | const YContract = artifacts.require('Y'); 3 | const BContract = artifacts.require('B'); 4 | const CContract = artifacts.require('C'); 5 | const DContract = artifacts.require('D'); 6 | const EContract = artifacts.require('E'); 7 | 8 | module.exports = function (deployer) { 9 | deployer.deploy(XContract, 'Hello X'); 10 | deployer.deploy(YContract, 'Hello Y'); 11 | deployer.deploy(BContract); 12 | deployer.deploy(CContract, 'Hello X', 'Hello Y'); 13 | deployer.deploy(DContract); 14 | deployer.deploy(EContract); 15 | }; 16 | -------------------------------------------------------------------------------- /applications/05-erc20/contracts/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | interface IERC20 { 5 | function totalSupply() external view returns (uint256); 6 | function balanceOf(address account) external view returns (uint256); 7 | function transfer(address recipient, uint256 amount) external returns (bool); 8 | function allowance(address owner, address spender) external view returns (uint256); 9 | function approve(address spender, uint256 amount) external returns (bool); 10 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 11 | } 12 | -------------------------------------------------------------------------------- /applications/12-upgradeable-proxy/migrations/2_upgradeable_proxy_migration.js: -------------------------------------------------------------------------------- 1 | const CounterV1 = artifacts.require('CounterV1'); 2 | const CounterV2 = artifacts.require('CounterV2'); 3 | const BuggyProxy = artifacts.require('BuggyProxy'); 4 | const Dev = artifacts.require('Dev'); 5 | const ProxyAdmin = artifacts.require('ProxyAdmin'); 6 | const TestSlot = artifacts.require('TestSlot'); 7 | 8 | module.exports = function (deployer) { 9 | deployer.deploy(CounterV1); 10 | deployer.deploy(CounterV2); 11 | deployer.deploy(BuggyProxy); 12 | deployer.deploy(Dev); 13 | deployer.deploy(ProxyAdmin); 14 | deployer.deploy(TestSlot); 15 | }; 16 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/test/assembly_variable.js: -------------------------------------------------------------------------------- 1 | const AssemblyVariable = artifacts.require('AssemblyVariable'); 2 | // const { expect } = require('chai'); 3 | // const truffleAssert = require('truffle-assertions'); 4 | 5 | contract('AssemblyVariable', (accounts) => { 6 | let assemblyVariableInstance; 7 | 8 | before(async () => { 9 | assemblyVariableInstance = await AssemblyVariable.new(); 10 | }); 11 | 12 | it('should return the correct value of z', async () => { 13 | const z = await assemblyVariableInstance.yul_let(); 14 | const expected = 456; 15 | assert.equal(z, expected, 'The result is incorrect'); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /basic/02-first-app/contracts/FirstApp.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract FirstApp { 5 | uint256 public count; 6 | 7 | constructor() { 8 | count = 0; 9 | } 10 | 11 | // Function to get the current count 12 | function get() public view returns (uint256) { 13 | return count; 14 | } 15 | 16 | // Function to increase count by 1 17 | function inc() public { 18 | count += 1; 19 | } 20 | 21 | // Function to decrease count by 1 22 | function dec() public { 23 | // This function will fail if count = 0 24 | count -= 1; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/test/factory.js: -------------------------------------------------------------------------------- 1 | const Factory = artifacts.require('Factory'); 2 | const IContract = artifacts.require('IContract'); 3 | 4 | contract('Factory', (accounts) => { 5 | it('should deploy a contract that returns 42', async () => { 6 | const factoryInstance = await Factory.deployed(); 7 | 8 | const tx = await factoryInstance.deploy(); 9 | const deployedAddress = tx.logs[0].args.addr; 10 | 11 | const contractInstance = await IContract.at(deployedAddress); 12 | const result = await contractInstance.getMeaningOfLife(); 13 | 14 | assert.equal(result.toNumber(), 42, 'Returned value is not 42'); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /basic/31-fallback/migrations/2_fallback_migration.js: -------------------------------------------------------------------------------- 1 | const FallbackContract = artifacts.require('Fallback'); 2 | const SendToFallbackContract = artifacts.require('SendToFallback'); 3 | const FallbackInputOutputContract = artifacts.require('FallbackInputOutput'); 4 | const CounterContract = artifacts.require('Counter'); 5 | const TestFallbackInputOutputContract = artifacts.require('TestFallbackInputOutput'); 6 | 7 | module.exports = function (deployer) { 8 | deployer.deploy(FallbackContract); 9 | deployer.deploy(SendToFallbackContract); 10 | // deployer.deploy(FallbackInputOutputContract); 11 | deployer.deploy(CounterContract); 12 | deployer.deploy(TestFallbackInputOutputContract); 13 | }; 14 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/contracts/ViewAndPure.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * Getter functions can be declared view or pure. 6 | * View function declares that no state will be changed. 7 | * Pure function declares that no state variable will be changed or read. 8 | */ 9 | contract ViewAndPure { 10 | uint256 public x = 1; 11 | 12 | // Promise not to modify the state. 13 | function addToX(uint256 y) public view returns (uint256) { 14 | return x + y; 15 | } 16 | 17 | // Promise not to modify or read from the state. 18 | function add(uint256 i, uint256 j) public pure returns (uint256) { 19 | return i + j; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/12-mapping/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/13-array/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/14-enum/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/15-structs/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/20-error/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/22-events/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/29-payable/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/32-call/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/38-import/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/39-library/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/test/most_significant_bit_assembly.js: -------------------------------------------------------------------------------- 1 | const MostSignificantBitAssembly = artifacts.require('MostSignificantBitAssembly'); 2 | 3 | contract('MostSignificantBitAssembly', (accounts) => { 4 | let mostSignificantBitAssembly; 5 | 6 | before(async () => { 7 | mostSignificantBitAssembly = await MostSignificantBitAssembly.deployed(); 8 | }); 9 | 10 | it('should find the most significant bit correctly', async () => { 11 | const x = 0x1234567890abcdefn; 12 | const expected = 60; 13 | 14 | const result = await mostSignificantBitAssembly.mostSignificantBit(x); 15 | 16 | assert.equal(web3.utils.hexToNumber(result), expected, 'Most significant bit is incorrect'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/test/most_significant_bit_function.js: -------------------------------------------------------------------------------- 1 | const MostSignificantBitFunction = artifacts.require('MostSignificantBitFunction'); 2 | 3 | contract('MostSignificantBitFunction', (accounts) => { 4 | let mostSignificantBitFunction; 5 | 6 | before(async () => { 7 | mostSignificantBitFunction = await MostSignificantBitFunction.deployed(); 8 | }); 9 | 10 | it('should find the most significant bit correctly', async () => { 11 | const x = 0x1234567890abcdefn; 12 | const expected = 60; 13 | 14 | const result = await mostSignificantBitFunction.mostSignificantBit(x); 15 | 16 | assert.equal(web3.utils.hexToNumber(result), expected, 'Most significant bit is incorrect'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /applications/05-erc20/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/01-hello-world/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/02-first-app/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/04-variables/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/05-constants/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/06-immutable/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/10-if-and-else/contracts/IfElse.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract IfElse { 5 | function foo(uint256 x) public pure returns (uint256) { 6 | if (x < 10) { 7 | return 0; 8 | } else if (x < 20) { 9 | return 1; 10 | } else { 11 | return 2; 12 | } 13 | } 14 | 15 | function ternary(uint256 _x) public pure returns (uint256) { 16 | // if (_x < 10) { 17 | // return 1; 18 | // } 19 | // return 2; 20 | 21 | // shorthand way to write if / else statement 22 | // the "?" operator is called the ternary operator 23 | return _x < 10 ? 1 : 2; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /basic/10-if-and-else/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/18-function/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/test/TestViewAndPure.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "truffle/Assert.sol"; 5 | import "../contracts/ViewAndPure.sol"; 6 | 7 | contract TestViewAndPure { 8 | ViewAndPure public contractInstance; 9 | 10 | function beforeEach() public { 11 | contractInstance = new ViewAndPure(); 12 | } 13 | 14 | function testAddToX() external { 15 | uint256 result = contractInstance.addToX(100); 16 | Assert.equal(result, 101, "Incorrect result"); 17 | } 18 | 19 | function testAdd() external { 20 | uint256 result = contractInstance.add(1, 2); 21 | Assert.equal(result, 3, "Incorrect result"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /basic/23-constructor/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/24-inheritance/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/27-visibility/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/28-interface/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/31-fallback/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/33-delegatecall/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/37-try-catch/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/40-abi-encode/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/41-abi-decode/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/06-erc721/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/07-erc1155/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/16-data-locations/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/17-transient-storage/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/21-function-modifier/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/30-sending-ether/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/34-function-selector/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/47-assembly-variable/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/50-assembly-error/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/51-assembly-math/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/01-ether-wallet/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/03-primary-data-types/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/22-events/contracts/Event.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * Events allow logging to the Ethereum blockchain. Some use cases for events are: 6 | * - Listening for events and updating user interface 7 | * - A cheap form of storage 8 | */ 9 | contract Event { 10 | // Event declaration 11 | // Up to 3 parameters can be indexed. 12 | // Indexed parameters helps you filter the logs by the indexed parameter 13 | event Log(address indexed sender, string message); 14 | event AnotherLog(); 15 | 16 | function test() public { 17 | emit Log(msg.sender, "Hello World!"); 18 | emit Log(msg.sender, "Hello EVM!"); 19 | emit AnotherLog(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/42-hashing-with-keccak256/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/44-gas-saving-techniques/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/02-multi-sig-wallet/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/04-iterable-mapping/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/12-upgradeable-proxy/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/13-deploy-any-contract/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/contracts/SimpleStorage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // To write or update a state variable you need to send a transaction. 5 | // On the other hand, you can read state variables, for free, without any transaction fee. 6 | contract SimpleStorage { 7 | // State variable to store a number 8 | uint256 public num; 9 | 10 | // You need to send a transaction to write to a state variable. 11 | function set(uint256 _num) public { 12 | num = _num; 13 | } 14 | 15 | // You can read from a state variable without sending a transaction. 16 | function get() public view returns (uint256) { 17 | return num; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /basic/19-view-and-pure-functions/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/26-calling-parent-contracts/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/09-simple-bytecode-contract/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/15-structs/test/TestStructImport.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../contracts/StructImport.sol"; 5 | import "../contracts/StructDeclaration.sol"; 6 | 7 | contract TodosImportTest { 8 | TodosImport public todosImportContract; 9 | 10 | function beforeEach() public { 11 | todosImportContract = new TodosImport(); 12 | } 13 | 14 | function testTodos() external { 15 | // Create a new todo 16 | todosImportContract.push(Todo("Buy groceries", false)); 17 | 18 | // Retrieve the todo details 19 | Todo memory todo = todosImportContract.get()[0]; 20 | assert(bytes(todo.text).length > 0); 21 | assert(!todo.completed); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/36-contract-that-creates-other-contracts/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/test/assembly_loop.js: -------------------------------------------------------------------------------- 1 | // testAssemblyLoop.js 2 | const AssemblyLoop = artifacts.require('AssemblyLoop'); 3 | 4 | contract('AssemblyLoop', (accounts) => { 5 | it('should return 10 using a for loop', async () => { 6 | const instance = await AssemblyLoop.deployed(); 7 | const expectedZ = 10; 8 | 9 | const result = await instance.yul_for_loop(); 10 | assert.equal(result, expectedZ, 'Unexpected value of z'); 11 | }); 12 | 13 | it('should return 5 using a while loop', async () => { 14 | const instance = await AssemblyLoop.deployed(); 15 | const expectedZ = 5; 16 | 17 | const result = await instance.yul_while_loop(); 18 | assert.equal(result, expectedZ, 'Unexpected value of z'); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /basic/07-reading-and-writing-to-a-state-variable/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.4.22 <0.9.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require(msg.sender == owner, "This function is restricted to the contract's owner"); 10 | _; 11 | } 12 | 13 | function setCompleted(uint completed) public restricted { 14 | last_completed_migration = completed; 15 | } 16 | 17 | function upgrade(address new_address) public restricted { 18 | Migrations upgraded = Migrations(new_address); 19 | upgraded.setCompleted(last_completed_migration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /basic/49-assembly-loop/contracts/AssemblyLoop.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract AssemblyLoop { 5 | function yul_for_loop() public pure returns (uint256 z) { 6 | assembly { 7 | for { 8 | let i := 0 9 | } lt(i, 10) { 10 | i := add(i, 1) 11 | } { 12 | z := add(z, 1) 13 | } 14 | } 15 | } 16 | 17 | function yul_while_loop() public pure returns (uint256 z) { 18 | assembly { 19 | let i := 0 20 | for { 21 | 22 | } lt(i, 5) { 23 | 24 | } { 25 | i := add(i, 1) 26 | z := add(z, 1) 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /basic/05-constants/test/constants.js: -------------------------------------------------------------------------------- 1 | const Constants = artifacts.require('Constants'); 2 | 3 | contract('Constants', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await Constants.deployed(); 8 | }); 9 | 10 | it('should display `0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc`', async () => { 11 | const myAddress = await contractInstance.MY_ADDRESS(); 12 | assert.equal( 13 | myAddress, 14 | '0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc', 15 | "0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc wasn't displayed", 16 | ); 17 | }); 18 | 19 | it('should display `123`', async () => { 20 | const myUint = await contractInstance.MY_UINT(); 21 | assert.equal(myUint, 123, "123 wasn't displayed"); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /basic/04-variables/contracts/Variables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract Variables { 5 | uint256 public timestamp = block.timestamp; // Current block timestamp 6 | address public sender = msg.sender; // address of the caller 7 | // State variables are stored on the blockchain. 8 | string public text = "Hello"; 9 | uint256 public num = 123; 10 | 11 | function getLocalValue() public pure returns (uint256) { 12 | // Local variables are not saved to the blockchain. 13 | uint256 i = 456; 14 | return i; 15 | } 16 | 17 | function getSender() public view returns (address) { 18 | return msg.sender; 19 | } 20 | 21 | function getTimestamp() public view returns (uint256) { 22 | return block.timestamp; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /basic/02-first-app/test/first_app.js: -------------------------------------------------------------------------------- 1 | const FirstAppContract = artifacts.require('FirstApp'); 2 | 3 | contract('FirstApp', (accounts) => { 4 | let firstAppContractInstance; 5 | 6 | before(async () => { 7 | firstAppContractInstance = await FirstAppContract.deployed(); 8 | }); 9 | 10 | it('should display 10', async () => { 11 | for (let i = 0; i < 10; i++) { 12 | await firstAppContractInstance.inc(); 13 | } 14 | const ten = await firstAppContractInstance.get(); 15 | 16 | assert.equal(ten, 10, "10 wasn't displayed"); 17 | }); 18 | 19 | it('should display 5', async () => { 20 | for (let i = 5; i > 0; i--) { 21 | await firstAppContractInstance.dec(); 22 | } 23 | const ten = await firstAppContractInstance.get(); 24 | 25 | assert.equal(ten, 5, "5 wasn't displayed"); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /basic/38-import/test/import.js: -------------------------------------------------------------------------------- 1 | // Import the contract artifacts and the necessary modules 2 | const Import = artifacts.require('Import'); 3 | const Foo = artifacts.require('Foo'); 4 | 5 | contract('Import', (accounts) => { 6 | let importInstance; 7 | let fooInstance; 8 | 9 | beforeEach(async () => { 10 | // Deploy the Foo contract 11 | fooInstance = await Foo.new(); 12 | // Deploy the Import contract and pass the address of the Foo contract 13 | importInstance = await Import.new(fooInstance.address); 14 | }); 15 | 16 | it('should import and interact with Foo contract', async () => { 17 | // Call getFooName to retrieve the name of the Foo contract 18 | const fooName = await importInstance.getFooName(); 19 | assert.equal(fooName, 'Foo', 'Expected Foo contract name to be "Foo Contract"'); 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /basic/41-abi-decode/contracts/AbiDecode.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract AbiDecode { 5 | struct MyStruct { 6 | string name; 7 | uint256[2] nums; 8 | } 9 | 10 | function encode( 11 | uint256 x, 12 | address addr, 13 | uint256[] calldata arr, 14 | MyStruct calldata myStruct 15 | ) external pure returns (bytes memory) { 16 | return abi.encode(x, addr, arr, myStruct); 17 | } 18 | 19 | function decode( 20 | bytes calldata data 21 | ) external pure returns (uint256 x, address addr, uint256[] memory arr, MyStruct memory myStruct) { 22 | // (uint x, address addr, uint[] memory arr, MyStruct myStruct) = ... 23 | (x, addr, arr, myStruct) = abi.decode(data, (uint256, address, uint256[], MyStruct)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /applications/03-merkle-tree/test/test_merkel_proof.js: -------------------------------------------------------------------------------- 1 | const TestMerkleProof = artifacts.require('TestMerkleProof'); 2 | 3 | contract('TestMerkleProof', (accounts) => { 4 | it('should verify the Merkle proof', async () => { 5 | const contractInstance = await TestMerkleProof.deployed(); 6 | 7 | const proof = [ 8 | '0x8da9e1c820f9dbd1589fd6585872bc1063588625729e7ab0797cfc63a00bd950', 9 | '0x995788ffc103b987ad50f5e5707fd094419eb12d9552cc423bd0cd86a3861433', 10 | ]; 11 | const root = '0xcc086fcc038189b4641db2cc4f1de3bb132aefbd65d510d817591550937818c7'; 12 | const leaf = '0xdca3326ad7e8121bf9cf9c12333e6b2271abe823ec9edfe42f813b1e768fa57b'; 13 | const index = 2; 14 | 15 | const result = await contractInstance.verify(proof, root, leaf, index); 16 | assert.equal(result, true, 'Merkle proof verification failed'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/contracts/AssemblyIf.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract AssemblyIf { 5 | function yul_if(uint256 x) public pure returns (uint256 z) { 6 | assembly { 7 | // if condition = 1 { code } 8 | // no else 9 | // if 0 { z := 99 } 10 | // if 1 { z := 99 } 11 | if lt(x, 10) { 12 | z := 99 13 | } 14 | } 15 | } 16 | 17 | function yul_switch(uint256 x) public pure returns (uint256 z) { 18 | assembly { 19 | switch x 20 | case 1 { 21 | z := 10 22 | } 23 | case 2 { 24 | z := 20 25 | } 26 | default { 27 | z := 0 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /basic/40-abi-encode/test/abi_encode.js: -------------------------------------------------------------------------------- 1 | // Import the contract artifacts 2 | const AbiEncode = artifacts.require('AbiEncode'); 3 | 4 | contract('AbiEncode', (accounts) => { 5 | it('should test the ABI encoding and function calls', async () => { 6 | const abiEncodeInstance = await AbiEncode.deployed(); 7 | 8 | // Test encodeWithSignature function 9 | const data1 = await abiEncodeInstance.encodeWithSignature(accounts[1], 100); 10 | console.log('Encoded data with signature:', data1); 11 | 12 | // Test encodeWithSelector function 13 | const data2 = await abiEncodeInstance.encodeWithSelector(accounts[2], 200); 14 | console.log('Encoded data with selector:', data2); 15 | 16 | // Test encodeCall function 17 | const data3 = await abiEncodeInstance.encodeCall(accounts[3], 300); 18 | console.log('Encoded data for function call:', data3); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /basic/25-shadowing-inherited-state-variables/contracts/ShadowingInherits.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * Unlike functions, state variables cannot be overridden by re-declaring it in the child contract. 6 | * Let's learn how to correctly override inherited state variables. 7 | */ 8 | 9 | contract A { 10 | string public name = "Contract A"; 11 | 12 | function getName() public view returns (string memory) { 13 | return name; 14 | } 15 | } 16 | 17 | // Shadowing is disallowed in Solidity 0.6 18 | // This will not compile 19 | // contract B is A { 20 | // string public name = "Contract B"; 21 | // } 22 | 23 | contract C is A { 24 | // This is the correct way to override inherited state variables. 25 | constructor() { 26 | name = "Contract C"; 27 | } 28 | 29 | // C.getName returns "Contract C" 30 | } 31 | -------------------------------------------------------------------------------- /basic/11-for-and-while-loop/contracts/Loop.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * Solidity supports for, while, and do while loops. 6 | * Don't write loops that are unbounded as this can hit the gas limit, causing your transaction to fail. 7 | * For the reason above, while and do while loops are rarely used. 8 | */ 9 | contract Loop { 10 | function loop() public pure { 11 | // for loop 12 | for (uint256 i = 0; i < 10; i++) { 13 | if (i == 3) { 14 | // Skip to next iteration with continue 15 | continue; 16 | } 17 | if (i == 5) { 18 | // Exit loop with break 19 | break; 20 | } 21 | } 22 | 23 | // while loop 24 | uint256 j; 25 | while (j < 10) { 26 | j++; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /basic/08-ether-and-wei/test/ether_units.js: -------------------------------------------------------------------------------- 1 | const EtherUnitsContract = artifacts.require('EtherUnits'); 2 | 3 | contract('Ethereum Units', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await EtherUnitsContract.deployed(); 8 | }); 9 | 10 | it('should display `1 wei`', async () => { 11 | const value = await contractInstance.oneWei(); 12 | assert.equal(value, 1); 13 | }); 14 | 15 | it('should display `1 wei == 1`', async () => { 16 | const value = await contractInstance.isOneWei(); 17 | assert.equal(value, true); 18 | }); 19 | 20 | it('should display `1 ether`', async () => { 21 | const value = await contractInstance.oneEther(); 22 | assert.equal(value, 10n ** 18n); 23 | }); 24 | 25 | it('should display `1 ether == 1e18`', async () => { 26 | const value = await contractInstance.isOneEther(); 27 | assert.equal(value, true); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /applications/08-gasless-token-transfer/test/erc20_permit.js: -------------------------------------------------------------------------------- 1 | const ERC20Permit = artifacts.require('ERC20Permit'); 2 | 3 | contract('ERC20Permit', (accounts) => { 4 | let erc20; 5 | 6 | before(async () => { 7 | erc20 = await ERC20Permit.new('MyToken', 'MTK', 18); 8 | }); 9 | 10 | it('should have correct name, symbol, and decimals', async () => { 11 | const name = await erc20.name(); 12 | const symbol = await erc20.symbol(); 13 | const decimals = await erc20.decimals(); 14 | 15 | assert.equal(name, 'MyToken'); 16 | assert.equal(symbol, 'MTK'); 17 | assert.equal(decimals, 18); 18 | }); 19 | 20 | it('should mint tokens to an address', async () => { 21 | const amount = web3.utils.toWei('100', 'ether'); 22 | const to = accounts[1]; 23 | 24 | await erc20.mint(to, amount); 25 | 26 | const balance = await erc20.balanceOf(to); 27 | 28 | assert.equal(balance.toString(), amount); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /basic/24-inheritance/test/TestInheritance.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "truffle/Assert.sol"; 5 | import "../contracts/Inheritance.sol"; 6 | 7 | contract TestInheritance { 8 | D public d; 9 | E public e; 10 | F public f; 11 | 12 | function beforeEach() public { 13 | d = new D(); 14 | e = new E(); 15 | f = new F(); 16 | } 17 | 18 | function testD() public { 19 | string memory expected = "C"; 20 | 21 | Assert.equal(d.foo(), expected, "Incorrect result in contract D"); 22 | } 23 | 24 | function testE() public { 25 | string memory expected = "B"; 26 | 27 | Assert.equal(e.foo(), expected, "Incorrect result in contract E"); 28 | } 29 | 30 | function testF() public { 31 | string memory expected = "B"; 32 | 33 | Assert.equal(f.foo(), expected, "Incorrect result in contract F"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/contracts/UncheckedMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract UncheckedMath { 5 | function add(uint256 x, uint256 y) external pure returns (uint256) { 6 | // 22291 gas 7 | // return x + y; 8 | 9 | // 22103 gas 10 | unchecked { 11 | return x + y; 12 | } 13 | } 14 | 15 | function sub(uint256 x, uint256 y) external pure returns (uint256) { 16 | // 22329 gas 17 | // return x - y; 18 | 19 | // 22147 gas 20 | unchecked { 21 | return x - y; 22 | } 23 | } 24 | 25 | function sumOfCubes(uint256 x, uint256 y) external pure returns (uint256) { 26 | // Wrap complex math logic inside unchecked 27 | unchecked { 28 | uint256 x3 = x * x * x; 29 | uint256 y3 = y * y * y; 30 | 31 | return x3 + y3; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /applications/10-precompute-contract-address-width-create2/test/create2.js: -------------------------------------------------------------------------------- 1 | const Factory = artifacts.require('Factory'); 2 | const TestContract = artifacts.require('TestContract'); 3 | 4 | contract('Factory', (accounts) => { 5 | it('should deploy a new TestContract', async () => { 6 | const factoryInstance = await Factory.deployed(); 7 | 8 | const owner = accounts[0]; 9 | const foo = 123; 10 | const salt = web3.utils.randomHex(32); 11 | 12 | const deployedAddress = await factoryInstance.deploy.call(owner, foo, salt); 13 | await factoryInstance.deploy(owner, foo, salt); 14 | 15 | const testContractInstance = await TestContract.at(deployedAddress); 16 | const deployedOwner = await testContractInstance.owner(); 17 | const deployedFoo = await testContractInstance.foo(); 18 | 19 | assert.equal(deployedOwner, owner, 'Owner address is incorrect'); 20 | assert.equal(deployedFoo.toNumber(), foo, 'Foo value is incorrect'); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /basic/50-assembly-error/test/assembly_error.js: -------------------------------------------------------------------------------- 1 | // testAssemblyError.js 2 | const AssemblyError = artifacts.require('AssemblyError'); 3 | 4 | contract('AssemblyError', (accounts) => { 5 | it('should revert if x is greater than 10', async () => { 6 | const instance = await AssemblyError.deployed(); 7 | const x = 15; 8 | 9 | try { 10 | await instance.yul_revert(x); 11 | assert.fail('Expected revert not received'); 12 | } catch (error) { 13 | const revertFound = error.message.search('revert') >= 0; 14 | assert(revertFound, `Expected "revert" error but got ${error} instead`); 15 | } 16 | }); 17 | 18 | it('should not revert if x is less than or equal to 10', async () => { 19 | const instance = await AssemblyError.deployed(); 20 | const x = 8; 21 | 22 | try { 23 | await instance.yul_revert(x); 24 | } catch (error) { 25 | assert.fail(`Reverted unexpectedly with error: ${error}`); 26 | } 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /basic/28-interface/test/TestInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | import "truffle/Assert.sol"; 5 | import "../contracts/Interface.sol"; 6 | 7 | contract TestInterface { 8 | MyContract public myContract; 9 | Counter public counter; 10 | 11 | function beforeEach() public { 12 | counter = new Counter(); 13 | myContract = new MyContract(); 14 | } 15 | 16 | function testIncrementCounter() public { 17 | uint256 initialCount = counter.count(); 18 | myContract.incrementCounter(address(counter)); 19 | uint256 newCount = counter.count(); 20 | 21 | Assert.equal(newCount, initialCount + 1, "Counter not incremented correctly"); 22 | } 23 | 24 | function testGetCount() public { 25 | counter.increment(); 26 | uint256 count = myContract.getCount(address(counter)); 27 | 28 | Assert.equal(count, counter.count(), "Incorrect count retrieved"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /basic/35-calling-other-contract/contracts/CallingOtherContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract Callee { 5 | uint256 public x; 6 | uint256 public value; 7 | 8 | function setX(uint256 _x) public returns (uint256) { 9 | x = _x; 10 | return x; 11 | } 12 | 13 | function setXandSendEther(uint256 _x) public payable returns (uint256, uint256) { 14 | x = _x; 15 | value = msg.value; 16 | 17 | return (x, value); 18 | } 19 | } 20 | 21 | contract Caller { 22 | function setX(Callee _callee, uint256 _x) public { 23 | uint256 x = _callee.setX(_x); 24 | } 25 | 26 | function setXFromAddress(address _addr, uint256 _x) public { 27 | Callee callee = Callee(_addr); 28 | callee.setX(_x); 29 | } 30 | 31 | function setXandSendEther(Callee _callee, uint256 _x) public payable { 32 | (uint256 x, uint256 value) = _callee.setXandSendEther{value: msg.value}(_x); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /basic/13-array/contracts/ArrayReplaceFromEnd.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract ArrayReplaceFromEnd { 5 | uint256[] public arr; 6 | 7 | // Deleting an element creates a gap in the array. 8 | // One trick to keep the array compact is to 9 | // move the last element into the place to delete. 10 | function remove(uint256 index) public { 11 | // Move the last element into the place to delete 12 | arr[index] = arr[arr.length - 1]; 13 | // Remove the last element 14 | arr.pop(); 15 | } 16 | 17 | function test() public { 18 | arr = [1, 2, 3, 4]; 19 | 20 | remove(1); 21 | // [1, 4, 3] 22 | assert(arr.length == 3); 23 | assert(arr[0] == 1); 24 | assert(arr[1] == 4); 25 | assert(arr[2] == 3); 26 | 27 | remove(2); 28 | // [1, 4] 29 | assert(arr.length == 2); 30 | assert(arr[0] == 1); 31 | assert(arr[1] == 4); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /basic/43-verifying-signature/test/verify_signature.js: -------------------------------------------------------------------------------- 1 | // Import the contract artifacts and the necessary modules 2 | const VerifySignature = artifacts.require('VerifySignature'); 3 | 4 | contract('VerifySignature', (accounts) => { 5 | let verifySignature; 6 | 7 | before(async () => { 8 | verifySignature = await VerifySignature.deployed(); 9 | }); 10 | 11 | it('should verify the signature correctly', async () => { 12 | const signer = '0xB273216C05A8c0D4F0a4Dd0d7Bae1D2EfFE636dd'; 13 | const to = '0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C'; 14 | const amount = 123; 15 | const message = 'coffee and donuts'; 16 | const nonce = 1; 17 | const signature = 18 | '0x993dab3dd91f5c6dc28e17439be475478f5635c92a56e17e82349d3fb2f166196f466c0b4e0c146f285204f0dcb13e5ae67bc33f4b888ec32dfe0a063e8f3f781b'; 19 | 20 | const result = await verifySignature.verify(signer, to, amount, message, nonce, signature); 21 | assert.equal(result, true, 'Signature verification failed'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /basic/20-error/contracts/Account.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract Account { 5 | uint256 public balance; 6 | uint256 public constant MAX_UINT = 2 ** 256 - 1; 7 | 8 | function deposit(uint256 _amount) public { 9 | uint256 oldBalance = balance; 10 | uint256 newBalance = balance + _amount; 11 | 12 | // balance + _amount does not overflow if balance + _amount > balance 13 | require(newBalance > oldBalance, "Overflow"); 14 | 15 | balance = newBalance; 16 | 17 | assert(balance > oldBalance); 18 | } 19 | 20 | function withdraw(uint256 _amount) public { 21 | uint256 oldBalance = balance; 22 | 23 | // balance - _amount does not underflow if balance >= _amount 24 | require(balance > _amount, "Underflow"); 25 | 26 | if (balance < _amount) { 27 | revert("Underflow"); 28 | } 29 | 30 | balance -= _amount; 31 | 32 | assert(balance < oldBalance); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /basic/16-data-locations/test/TestDataLocations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../contracts/DataLocations.sol"; 5 | 6 | contract TestDataLocations { 7 | DataLocations public dataLocationsContract; 8 | 9 | function beforeEach() public { 10 | dataLocationsContract = new DataLocations(); 11 | } 12 | 13 | function testDataLocations() external { 14 | // Call function f in DataLocations contract 15 | dataLocationsContract.f(); 16 | 17 | uint256[] memory arr = new uint256[](5); 18 | for (uint256 i = 0; i < arr.length; i++) { 19 | arr[i] = (i > 0 ? arr[i - 1] : 0) + i; 20 | } 21 | 22 | // Call function g in DataLocations contract 23 | uint256[] memory arrResult = dataLocationsContract.g(arr); 24 | 25 | // Assert that the returned array has been modified 26 | assert(arrResult.length > 0); 27 | 28 | // Call function h in DataLocations contract 29 | dataLocationsContract.h(arr); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /basic/10-if-and-else/test/if_else.js: -------------------------------------------------------------------------------- 1 | const IfElseContract = artifacts.require('IfElse'); 2 | 3 | contract('If Else', (accounts) => { 4 | let contractInstance; 5 | 6 | before(async () => { 7 | contractInstance = await IfElseContract.deployed(); 8 | }); 9 | 10 | it('should display `0`, if 5 < 10', async () => { 11 | const value = await contractInstance.foo(5); 12 | assert.equal(value, 0); 13 | }); 14 | 15 | it('should display `1`, else if 15 < 20', async () => { 16 | const value = await contractInstance.foo(15); 17 | assert.equal(value, 1); 18 | }); 19 | 20 | it('should display `2`, else', async () => { 21 | const value = await contractInstance.foo(25); 22 | assert.equal(value, 2); 23 | }); 24 | 25 | it('should display `1`, ternary 5 < 10', async () => { 26 | const value = await contractInstance.ternary(5); 27 | assert.equal(value, 1); 28 | }); 29 | 30 | it('should display `2`, ternary 15 > 10', async () => { 31 | const value = await contractInstance.ternary(15); 32 | assert.equal(value, 2); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /basic/01-hello-world/test/hello_world.js: -------------------------------------------------------------------------------- 1 | const HelloWorldContract = artifacts.require('HelloWorld'); 2 | 3 | contract('HelloWorld', (accounts) => { 4 | let helloWorldContractInstance; 5 | 6 | before(async () => { 7 | helloWorldContractInstance = await HelloWorldContract.deployed(); 8 | }); 9 | 10 | it('should display `Hello, World!`', async () => { 11 | const message = await helloWorldContractInstance.getMessage(); 12 | 13 | // Assert the result 14 | assert.equal(message, 'Hello, World!', "`Hello, World!` wasn't displayed"); 15 | }); 16 | 17 | it('should display `Welcome to solidity!`', async () => { 18 | const initialValue = await helloWorldContractInstance.getMessage(); 19 | 20 | await helloWorldContractInstance.setMessage('Welcome to solidity!'); 21 | 22 | const message = await helloWorldContractInstance.getMessage(); 23 | 24 | // Assert the result 25 | assert.equal(message, 'Welcome to solidity!', "`Welcome to solidity!` wasn't displayed"); 26 | assert.notEqual(message, initialValue, "message wasn't updated"); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /basic/33-delegatecall/contracts/Delegatecall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * delegatecall is a low level function similar to call. 6 | * When contract A executes delegatecall to contract B, B's code is executed 7 | * with contract A's storage, msg.sender and msg.value. 8 | */ 9 | 10 | // NOTE: Deploy this contract first 11 | contract B { 12 | // NOTE: storage layout must be the same as contract A 13 | uint256 public num; 14 | address public sender; 15 | uint256 public value; 16 | 17 | function setVars(uint256 _num) public payable { 18 | num = _num; 19 | sender = msg.sender; 20 | value = msg.value; 21 | } 22 | } 23 | 24 | contract A { 25 | uint256 public num; 26 | address public sender; 27 | uint256 public value; 28 | 29 | function setVars(address _contract, uint256 _num) public payable { 30 | // A's storage is set, B is not modified. 31 | (bool success, bytes memory data) = _contract.delegatecall(abi.encodeWithSignature("setVars(uint256)", _num)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /basic/34-function-selector/contracts/FunctionSelector.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * When a function is called, the first 4 bytes of calldata specifies which function to call. 6 | * This 4 bytes is called a function selector. 7 | * Take for example, this code below. It uses call to execute transfer on a contract at the address addr. 8 | * ```solidity 9 | * addr.call(abi.encodeWithSignature("transfer(address,uint256)", 0xSomeAddress, 123)) 10 | * ``` 11 | * The first 4 bytes returned from abi.encodeWithSignature(....) is the function selector. 12 | * Perhaps you can save a tiny amount of gas if you precompute and inline the function selector in your code? 13 | * Here is how the function selector is computed. 14 | */ 15 | contract FunctionSelector { 16 | /** 17 | * "transfer(address,uint256)" 18 | * 0xa9059cbb 19 | * "transferFrom(address,address,uint256)" 20 | * 0x23b872dd 21 | */ 22 | function getSelector(string calldata _func) external pure returns (bytes4) { 23 | return bytes4(keccak256(bytes(_func))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.updateImportsOnFileMove.enabled": "never", 3 | "typescript.preferences.importModuleSpecifier": "non-relative", 4 | "workbench.colorCustomizations": { 5 | "titleBar.activeForeground": "#000000", 6 | "titleBar.inactiveForeground": "#000000cc", 7 | "titleBar.activeBackground": "#fc9d26", 8 | "titleBar.inactiveBackground": "#fc9d26cc" 9 | }, 10 | "editor.detectIndentation": false, 11 | "editor.defaultFormatter": "esbenp.prettier-vscode", 12 | "editor.formatOnSave": true, 13 | "[typescriptreact]": { 14 | "editor.defaultFormatter": "esbenp.prettier-vscode", 15 | "editor.formatOnSave": true 16 | }, 17 | "[typescript]": { 18 | "editor.defaultFormatter": "esbenp.prettier-vscode", 19 | "editor.formatOnSave": true 20 | }, 21 | "[json]": { 22 | "editor.defaultFormatter": "esbenp.prettier-vscode", 23 | "editor.formatOnSave": true 24 | }, 25 | "[solidity]": { 26 | "editor.defaultFormatter": "esbenp.prettier-vscode", 27 | "editor.formatOnSave": true, 28 | "editor.tabSize": 4 29 | }, 30 | "editor.tabSize": 2, 31 | "cSpell.words": [] 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 James Gates 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /applications/11-minimal-proxy-contract/test/minimal_proxy.js: -------------------------------------------------------------------------------- 1 | const MinimalProxy = artifacts.require('MinimalProxy'); 2 | 3 | contract('MinimalProxy', (accounts) => { 4 | let minimalProxyInstance; 5 | 6 | const targetContractAddress = '0x1234567890123456789012345678901234567890'; 7 | let clonedContractAddress; 8 | 9 | before(async () => { 10 | minimalProxyInstance = await MinimalProxy.deployed(); 11 | }); 12 | 13 | it('should clone the target contract', async () => { 14 | const result = await minimalProxyInstance.clone.call(targetContractAddress); 15 | clonedContractAddress = result; 16 | 17 | assert.ok(clonedContractAddress, 'Cloned contract address should exist'); 18 | }); 19 | 20 | it('should have the same code as the target contract', async () => { 21 | const targetContractCode = await web3.eth.getCode(targetContractAddress); 22 | const clonedContractCode = await web3.eth.getCode(clonedContractAddress); 23 | 24 | assert.equal( 25 | clonedContractCode, 26 | targetContractCode, 27 | 'Cloned contract should have the same code as the target contract', 28 | ); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /basic/14-enum/test/TestEnum.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | import "../contracts/Enum.sol"; 5 | 6 | contract TestEnum { 7 | Enum public enumContract; 8 | 9 | function beforeEach() public { 10 | enumContract = new Enum(); 11 | } 12 | 13 | function testEnum() external { 14 | // Initial status should be "Pending" 15 | Enum.Status initialStatus = enumContract.get(); 16 | assert(initialStatus == Enum.Status.Pending); 17 | 18 | // Update status to "Shipped" 19 | enumContract.set(Enum.Status.Shipped); 20 | Enum.Status updatedStatus = enumContract.get(); 21 | assert(updatedStatus == Enum.Status.Shipped); 22 | 23 | // Update status to "Canceled" 24 | enumContract.cancel(); 25 | Enum.Status canceledStatus = enumContract.get(); 26 | assert(canceledStatus == Enum.Status.Canceled); 27 | 28 | // Reset status to default value ("Pending") 29 | enumContract.reset(); 30 | Enum.Status resetStatus = enumContract.get(); 31 | assert(resetStatus == Enum.Status.Pending); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /basic/13-array/contracts/ArrayRemoveByShifting.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract ArrayRemoveByShifting { 5 | // [1, 2, 3] -- remove(1) --> [1, 3, 3] --> [1, 3] 6 | // [1, 2, 3, 4, 5, 6] -- remove(2) --> [1, 2, 4, 5, 6, 6] --> [1, 2, 4, 5, 6] 7 | // [1, 2, 3, 4, 5, 6] -- remove(0) --> [2, 3, 4, 5, 6, 6] --> [2, 3, 4, 5, 6] 8 | // [1] -- remove(0) --> [1] --> [] 9 | 10 | uint256[] public arr; 11 | 12 | function remove(uint256 _index) public { 13 | require(_index < arr.length, "index out of bound"); 14 | 15 | for (uint256 i = _index; i < arr.length - 1; i++) { 16 | arr[i] = arr[i + 1]; 17 | } 18 | arr.pop(); 19 | } 20 | 21 | function test() external { 22 | arr = [1, 2, 3, 4, 5]; 23 | remove(2); 24 | // [1, 2, 4, 5] 25 | assert(arr[0] == 1); 26 | assert(arr[1] == 2); 27 | assert(arr[2] == 4); 28 | assert(arr[3] == 5); 29 | assert(arr.length == 4); 30 | 31 | arr = [1]; 32 | remove(0); 33 | // [] 34 | assert(arr.length == 0); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /basic/15-structs/test/TestStructs.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../contracts/Structs.sol"; 5 | 6 | contract TestTodos { 7 | Todos public todosContract; 8 | 9 | function beforeEach() public { 10 | todosContract = new Todos(); 11 | } 12 | 13 | function testTodos() external { 14 | // Create a new todo 15 | todosContract.create("Buy groceries"); 16 | 17 | // Retrieve the todo details 18 | (string memory text, bool completed) = todosContract.get(0); 19 | assert(bytes(text).length > 0); 20 | assert(!completed); 21 | 22 | // Update the todo text 23 | todosContract.updateText(0, "Buy clothes"); 24 | 25 | // Retrieve the updated todo details 26 | (text, completed) = todosContract.get(0); 27 | assert(keccak256(bytes(text)) == keccak256("Buy clothes")); 28 | 29 | // Toggle the completed status of the todo 30 | todosContract.toggleCompleted(0); 31 | 32 | // Retrieve the updated todo details 33 | (text, completed) = todosContract.get(0); 34 | assert(completed); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /basic/51-assembly-math/test/assembly_math.js: -------------------------------------------------------------------------------- 1 | // testAssemblyMath.js 2 | const AssemblyMath = artifacts.require('AssemblyMath'); 3 | 4 | contract('AssemblyMath', (accounts) => { 5 | it('should add two numbers correctly', async () => { 6 | const instance = await AssemblyMath.deployed(); 7 | const x = 5; 8 | const y = 10; 9 | const expectedZ = 15; 10 | 11 | const result = await instance.yul_add(x, y); 12 | assert.equal(result, expectedZ, 'Unexpected value of z'); 13 | }); 14 | 15 | it('should multiply two numbers correctly', async () => { 16 | const instance = await AssemblyMath.deployed(); 17 | const x = 5; 18 | const y = 10; 19 | const expectedZ = 50; 20 | 21 | const result = await instance.yul_mul(x, y); 22 | assert.equal(result, expectedZ, 'Unexpected value of z'); 23 | }); 24 | 25 | it('should round to the nearest multiple of b correctly', async () => { 26 | const instance = await AssemblyMath.deployed(); 27 | const x = 90; 28 | const b = 100; 29 | const expectedZ = 100; 30 | 31 | const result = await instance.yul_fixed_point_round(x, b); 32 | assert.equal(result, expectedZ, 'Unexpected value of z'); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /basic/04-variables/test/variables.js: -------------------------------------------------------------------------------- 1 | const VariablesContract = artifacts.require('Variables'); 2 | 3 | contract('Variables', (accounts) => { 4 | let contractInstance; 5 | let sender; 6 | let timestamp; 7 | 8 | before(async () => { 9 | contractInstance = await VariablesContract.deployed(); 10 | sender = await contractInstance.sender(); 11 | timestamp = await contractInstance.timestamp(); 12 | }); 13 | 14 | it('should display text `Hello`', async () => { 15 | const text = await contractInstance.text(); 16 | assert.equal(text, 'Hello', "`Hello` wasn't displayed"); 17 | }); 18 | 19 | it('should display num `123`', async () => { 20 | const num = await contractInstance.num(); 21 | assert.equal(num, '123', "`123` wasn't displayed"); 22 | }); 23 | 24 | it('should display sender', async () => { 25 | const globalSender = await contractInstance.getSender(); 26 | assert.equal(sender, globalSender, "sender wasn't displayed"); 27 | }); 28 | 29 | it('should display timestamp', async () => { 30 | const blockTimestamp = await contractInstance.getTimestamp(); 31 | assert.notEqual(timestamp, blockTimestamp, "timestamp wasn't displayed"); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /applications/07-erc1155/test/my_multi_token.js: -------------------------------------------------------------------------------- 1 | const MyMultiToken = artifacts.require('MyMultiToken'); 2 | 3 | contract('MyMultiToken', (accounts) => { 4 | let myMultiToken; 5 | 6 | before(async () => { 7 | myMultiToken = await MyMultiToken.deployed(); 8 | }); 9 | 10 | it('should mint tokens', async () => { 11 | const tokenId = 1; 12 | const value = 100; 13 | const data = '0x'; 14 | 15 | const initialBalance = await myMultiToken.balanceOf(accounts[0], tokenId); 16 | 17 | await myMultiToken.mint(tokenId, value, data); 18 | 19 | const newBalance = await myMultiToken.balanceOf(accounts[0], tokenId); 20 | 21 | assert.equal(newBalance.toNumber(), initialBalance.toNumber() + value, 'Token balance is incorrect'); 22 | }); 23 | 24 | it('should burn tokens', async () => { 25 | const tokenId = 1; 26 | const value = 50; 27 | 28 | const initialBalance = await myMultiToken.balanceOf(accounts[0], tokenId); 29 | 30 | await myMultiToken.burn(tokenId, value); 31 | 32 | const newBalance = await myMultiToken.balanceOf(accounts[0], tokenId); 33 | 34 | assert.equal(newBalance.toNumber(), initialBalance.toNumber() - value, 'Token balance is incorrect'); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /basic/46-unchecked-math/test/unchecked_math.js: -------------------------------------------------------------------------------- 1 | const UncheckedMath = artifacts.require('UncheckedMath'); 2 | 3 | contract('UncheckedMath', (accounts) => { 4 | let uncheckedMath; 5 | 6 | before(async () => { 7 | uncheckedMath = await UncheckedMath.deployed(); 8 | }); 9 | 10 | it('should add two numbers without checking for overflow', async () => { 11 | const x = 2; 12 | const y = 3; 13 | const expected = 5; 14 | 15 | const result = await uncheckedMath.add(x, y); 16 | 17 | assert.equal(result, expected, 'Addition result is incorrect'); 18 | }); 19 | 20 | it('should subtract two numbers without checking for underflow', async () => { 21 | const x = 5; 22 | const y = 3; 23 | const expected = 2; 24 | 25 | const result = await uncheckedMath.sub(x, y); 26 | 27 | assert.equal(result, expected, 'Subtraction result is incorrect'); 28 | }); 29 | 30 | it('should calculate the sum of cubes without checking for overflow', async () => { 31 | const x = 2; 32 | const y = 3; 33 | const expected = 35; // 2^3 + 3^3 = 8 + 27 = 35 34 | 35 | const result = await uncheckedMath.sumOfCubes(x, y); 36 | 37 | assert.equal(result, expected, 'Sum of cubes is incorrect'); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /basic/40-abi-encode/contracts/AbiEncode.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | interface IERC20 { 5 | function transfer(address, uint256) external; 6 | } 7 | 8 | contract Token { 9 | function transfer(address, uint256) external {} 10 | } 11 | 12 | contract AbiEncode { 13 | function test(address _contract, bytes calldata data) external { 14 | (bool ok, ) = _contract.call(data); 15 | require(ok, "call failed"); 16 | } 17 | 18 | function encodeWithSignature(address to, uint256 amount) external pure returns (bytes memory) { 19 | // Typo is not checked - "transfer(address, uint)" 20 | return abi.encodeWithSignature("transfer(address,uint256)", to, amount); 21 | } 22 | 23 | function encodeWithSelector(address to, uint256 amount) external pure returns (bytes memory) { 24 | // Type is not checked - (IERC20.transfer.selector, true, amount) 25 | return abi.encodeWithSelector(IERC20.transfer.selector, to, amount); 26 | } 27 | 28 | function encodeCall(address to, uint256 amount) external pure returns (bytes memory) { 29 | // Typo and type errors will not compile 30 | return abi.encodeCall(IERC20.transfer, (to, amount)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /basic/14-enum/contracts/Enum.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * Solidity supports enumerables and they are useful to model choice and keep track of state. 6 | * Enums can be declared outside of a contract. 7 | */ 8 | contract Enum { 9 | // Enum representing shipping status 10 | enum Status { 11 | Pending, 12 | Shipped, 13 | Accepted, 14 | Rejected, 15 | Canceled 16 | } 17 | 18 | // Default value is the first element listed in 19 | // definition of the type, in this case "Pending" 20 | Status public status; 21 | 22 | // Returns uint 23 | // Pending - 0 24 | // Shipped - 1 25 | // Accepted - 2 26 | // Rejected - 3 27 | // Canceled - 4 28 | function get() public view returns (Status) { 29 | return status; 30 | } 31 | 32 | // Update status by passing uint into input 33 | function set(Status _status) public { 34 | status = _status; 35 | } 36 | 37 | // You can update to a specific enum like this 38 | function cancel() public { 39 | status = Status.Canceled; 40 | } 41 | 42 | // delete resets the enum to its first value, 0 43 | function reset() public { 44 | delete status; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /basic/09-gas-and-gas-price/contracts/Gas.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /** 5 | * Gas 6 | * How much `ether` do you need to pay for a transaction? 7 | * You pay `gas spent` * `gas price` amount of ether, where 8 | * - `gas` is a unit of computation 9 | * - `gas` spent is the total amount of `gas` used in a transaction 10 | * - `gas price` is how much `ether` you are willing to pay per gas 11 | * Transactions with higher gas price have higher priority to be included in a block. 12 | * Unspent gas will be refunded. 13 | * 14 | * Gas Limit 15 | * There are 2 upper bounds to the amount of gas you can spend 16 | * - gas limit (max amount of gas you're willing to use for your transaction, set by you) 17 | * - block gas limit (max amount of gas allowed in a block, set by the network) 18 | */ 19 | contract Gas { 20 | uint256 public i = 0; 21 | 22 | // Using up all of the gas that you send causes your transaction to fail. 23 | // State changes are undone. 24 | // Gas spent are not refunded. 25 | function looping(uint256 count) public { 26 | // Here we run a loop until all of the gas are spent 27 | // and the transaction fails 28 | while (i < count) { 29 | i += 1; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solidity-examples", 3 | "version": "0.1.0", 4 | "description": "This collection features a diverse range of real-world smart contract examples and projects written in Solidity, covering decentralized finance, NFTs, DAOs, gaming, supply chain management, tokenization, prediction markets, and identity verification systems.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "prepare": "husky", 9 | "commitlint": "commitlint --edit" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/james-gates-0212/solidity-examples.git" 14 | }, 15 | "keywords": [ 16 | "solidity", 17 | "examples", 18 | "ethereum" 19 | ], 20 | "author": "James Gates", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/james-gates-0212/solidity-examples/issues" 24 | }, 25 | "homepage": "https://github.com/james-gates-0212/solidity-examples#readme", 26 | "devDependencies": { 27 | "@commitlint/cli": "^19.2.1", 28 | "@commitlint/config-conventional": "^19.1.0", 29 | "commitlint": "^19.2.1", 30 | "commitlint-config-gitmoji": "^2.3.1", 31 | "husky": "^9.0.11", 32 | "prettier": "^3.2.5", 33 | "prettier-plugin-solidity": "^1.3.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /basic/45-bitwise-operators/contracts/MostSignificantBitFunction .sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract MostSignificantBitFunction { 5 | // Find most significant bit using binary search 6 | function mostSignificantBit(uint256 x) external pure returns (uint256 msb) { 7 | // x >= 2 ** 128 8 | if (x >= 0x100000000000000000000000000000000) { 9 | x >>= 128; 10 | msb += 128; 11 | } 12 | // x >= 2 ** 64 13 | if (x >= 0x10000000000000000) { 14 | x >>= 64; 15 | msb += 64; 16 | } 17 | // x >= 2 ** 32 18 | if (x >= 0x100000000) { 19 | x >>= 32; 20 | msb += 32; 21 | } 22 | // x >= 2 ** 16 23 | if (x >= 0x10000) { 24 | x >>= 16; 25 | msb += 16; 26 | } 27 | // x >= 2 ** 8 28 | if (x >= 0x100) { 29 | x >>= 8; 30 | msb += 8; 31 | } 32 | // x >= 2 ** 4 33 | if (x >= 0x10) { 34 | x >>= 4; 35 | msb += 4; 36 | } 37 | // x >= 2 ** 2 38 | if (x >= 0x4) { 39 | x >>= 2; 40 | msb += 2; 41 | } 42 | // x >= 2 ** 1 43 | if (x >= 0x2) msb += 1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /basic/34-function-selector/test/function_selector.js: -------------------------------------------------------------------------------- 1 | // Import the necessary dependencies 2 | const FunctionSelector = artifacts.require('FunctionSelector'); 3 | 4 | contract('FunctionSelector', () => { 5 | let functionSelectorInstance; 6 | 7 | beforeEach(async () => { 8 | // Deploy the contract 9 | functionSelectorInstance = await FunctionSelector.new(); 10 | }); 11 | 12 | it('should return the function selector for "transfer(address,uint256)"', async () => { 13 | const expectedSelector = '0xa9059cbb'; 14 | 15 | // Call the getSelector function 16 | const result = await functionSelectorInstance.getSelector('transfer(address,uint256)'); 17 | 18 | // Assert that the returned function selector is correct 19 | assert.strictEqual(result, expectedSelector, 'Returned function selector is incorrect'); 20 | }); 21 | 22 | it('should return the function selector for "transferFrom(address,address,uint256)"', async () => { 23 | const expectedSelector = '0x23b872dd'; 24 | 25 | // Call the getSelector function 26 | const result = await functionSelectorInstance.getSelector('transferFrom(address,address,uint256)'); 27 | 28 | // Assert that the returned function selector is correct 29 | assert.strictEqual(result, expectedSelector, 'Returned function selector is incorrect'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /basic/23-constructor/contracts/Constructor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // Base contract X 5 | contract X { 6 | string public name; 7 | 8 | constructor(string memory _name) { 9 | name = _name; 10 | } 11 | } 12 | 13 | // Base contract Y 14 | contract Y { 15 | string public text; 16 | 17 | constructor(string memory _text) { 18 | text = _text; 19 | } 20 | } 21 | 22 | // There are 2 ways to initialize parent contract with parameters. 23 | 24 | // Pass the parameters here in the inheritance list. 25 | contract B is X("Input to X"), Y("Input to Y") {} 26 | 27 | contract C is X, Y { 28 | // Pass the parameters here in the constructor, 29 | // similar to function modifiers. 30 | constructor(string memory _name, string memory _text) X(_name) Y(_text) {} 31 | } 32 | 33 | // Parent constructors are always called in the order of inheritance 34 | // regardless of the order of parent contracts listed in the 35 | // constructor of the child contract. 36 | 37 | // Order of constructors called: 38 | // 1. X 39 | // 2. Y 40 | // 3. D 41 | contract D is X, Y { 42 | constructor() X("X was called") Y("Y was called") {} 43 | } 44 | 45 | // Order of constructors called: 46 | // 1. X 47 | // 2. Y 48 | // 3. E 49 | contract E is X, Y { 50 | constructor() Y("Y was called") X("X was called") {} 51 | } 52 | -------------------------------------------------------------------------------- /basic/41-abi-decode/test/abi_decode.js: -------------------------------------------------------------------------------- 1 | const AbiDecode = artifacts.require('AbiDecode'); 2 | 3 | contract('AbiDecode', () => { 4 | let abiDecodeInstance; 5 | 6 | before(async () => { 7 | abiDecodeInstance = await AbiDecode.deployed(); 8 | }); 9 | 10 | it('should encode and decode values correctly', async () => { 11 | const x = 123; 12 | const addr = '0x1234567890123456789012345678901234567890'; 13 | const arr = [1, 2, 3]; 14 | const myStruct = { 15 | name: 'Test', 16 | nums: [10, 20], 17 | }; 18 | 19 | const encodedData = await abiDecodeInstance.encode(x, addr, arr, myStruct); 20 | const decodedData = await abiDecodeInstance.decode(encodedData); 21 | 22 | const decodedX = decodedData.x.toNumber(); 23 | const decodedAddr = decodedData.addr; 24 | const decodedArr = decodedData.arr.map((num) => num.toNumber()); 25 | const decodedStruct = { 26 | name: decodedData.myStruct.name, 27 | nums: decodedData.myStruct.nums.map((num) => Number(num)), 28 | }; 29 | 30 | assert.equal(decodedX, x, 'Decoded x does not match encoded x'); 31 | assert.equal(decodedAddr, addr, 'Decoded address does not match encoded address'); 32 | assert.deepEqual(decodedArr, arr, 'Decoded array does not match encoded array'); 33 | assert.deepEqual(decodedStruct, myStruct, 'Decoded struct does not match encoded struct'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /basic/48-assembly-conditional-statements/test/assembly_if.js: -------------------------------------------------------------------------------- 1 | // testAssemblyIf.js 2 | const AssemblyIf = artifacts.require('AssemblyIf'); 3 | 4 | contract('AssemblyIf', (accounts) => { 5 | it('should return 99 if x is less than 10', async () => { 6 | const instance = await AssemblyIf.deployed(); 7 | const x = 5; 8 | const expectedZ = 99; 9 | 10 | const result = await instance.yul_if(x); 11 | assert.equal(result, expectedZ, 'Unexpected value of z'); 12 | }); 13 | 14 | it('should return 10 if x is 1', async () => { 15 | const instance = await AssemblyIf.deployed(); 16 | const x = 1; 17 | const expectedZ = 10; 18 | 19 | const result = await instance.yul_switch(x); 20 | assert.equal(result, expectedZ, 'Unexpected value of z'); 21 | }); 22 | 23 | it('should return 20 if x is 2', async () => { 24 | const instance = await AssemblyIf.deployed(); 25 | const x = 2; 26 | const expectedZ = 20; 27 | 28 | const result = await instance.yul_switch(x); 29 | assert.equal(result, expectedZ, 'Unexpected value of z'); 30 | }); 31 | 32 | it('should return 0 if x is neither 1 nor 2', async () => { 33 | const instance = await AssemblyIf.deployed(); 34 | const x = 3; 35 | const expectedZ = 0; 36 | 37 | const result = await instance.yul_switch(x); 38 | assert.equal(result, expectedZ, 'Unexpected value of z'); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /basic/51-assembly-math/contracts/AssemblyMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract AssemblyMath { 5 | function yul_add(uint256 x, uint256 y) public pure returns (uint256 z) { 6 | assembly { 7 | z := add(x, y) 8 | if lt(z, x) { 9 | revert(0, 0) 10 | } 11 | } 12 | } 13 | 14 | function yul_mul(uint256 x, uint256 y) public pure returns (uint256 z) { 15 | assembly { 16 | switch x 17 | case 0 { 18 | z := 0 19 | } 20 | default { 21 | z := mul(x, y) 22 | if iszero(eq(div(z, x), y)) { 23 | revert(0, 0) 24 | } 25 | } 26 | } 27 | } 28 | 29 | // Round to nearest multiple of b 30 | function yul_fixed_point_round(uint256 x, uint256 b) public pure returns (uint256 z) { 31 | assembly { 32 | // b = 100 33 | // x = 90 34 | // z = 90 / 100 * 100 = 0, want z = 100 35 | // z := mul(div(x, b), b) 36 | 37 | let half := div(b, 2) 38 | z := add(x, half) 39 | z := mul(div(z, b), b) 40 | // x = 90 41 | // half = 50 42 | // z = 90 + 50 = 140 43 | // z = 140 / 100 * 100 = 100 44 | } 45 | } 46 | } 47 | --------------------------------------------------------------------------------