├── .github └── workflows │ └── ci.yml ├── 01-hello-world ├── Forc.lock ├── Forc.toml ├── readme.md ├── solidity │ └── HelloWorld.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── hello-world-abi.json │ ├── hello-world-storage_slots.json │ └── hello-world.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── hello-world-abi.json │ │ ├── hello-world-storage_slots.json │ │ └── hello-world.bin │ └── src │ └── main.sw ├── 02-counter ├── Forc.lock ├── Forc.toml ├── solidity │ └── Counter.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── counter-abi.json │ ├── counter-storage_slots.json │ └── counter.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── counter-abi.json │ │ ├── counter-storage_slots.json │ │ └── counter.bin │ └── src │ └── main.sw ├── 03-logging ├── Forc.lock ├── Forc.toml ├── solidity │ └── Event.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── logging-abi.json │ ├── logging-storage_slots.json │ └── logging.bin │ ├── out │ └── debug │ │ ├── logging-abi.json │ │ ├── logging-storage_slots.json │ │ └── logging.bin │ └── src │ └── main.sw ├── 04-storage ├── Forc.lock ├── Forc.toml ├── solidity │ └── Storage.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── storage-abi.json │ │ ├── storage-storage_slots.json │ │ └── storage.bin │ └── src │ └── main.sw ├── 05-conditional ├── Forc.lock ├── Forc.toml ├── solidity │ └── Conditional.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── conditional-abi.json │ │ ├── conditional-storage_slots.json │ │ └── conditional.bin │ └── src │ └── main.sw ├── 06-structs ├── Forc.lock ├── Forc.toml ├── solidity │ └── structs.sol └── sway │ ├── .gitignore │ ├── Forc.lock │ ├── Forc.toml │ └── src │ └── main.sw ├── 07-errors ├── Forc.lock ├── Forc.toml ├── solidity │ └── Errors.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── errors-abi.json │ │ ├── errors-storage_slots.json │ │ └── errors.bin │ └── src │ └── main.sw ├── 08-functions ├── Forc.lock ├── Forc.toml ├── solidity │ └── Functions.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── functions-abi.json │ ├── functions-storage_slots.json │ └── functions.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── functions-abi.json │ │ ├── functions-storage_slots.json │ │ └── functions.bin │ └── src │ └── main.sw ├── 09-amounts ├── Forc.lock ├── Forc.toml ├── solidity │ └── Amounts.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── amounts-abi.json │ │ ├── amounts-storage_slots.json │ │ └── amounts.bin │ └── src │ └── main.sw ├── 10-message-info ├── Forc.lock ├── Forc.toml ├── solidity │ └── Message.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── message-info-abi.json │ │ ├── message-info-storage_slots.json │ │ └── message-info.bin │ └── src │ └── main.sw ├── 10.5.0 ├── 11-gas-info ├── Forc.lock ├── Forc.toml ├── solidity │ └── Gas.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── gas-info-abi.json │ ├── gas-info-storage_slots.json │ └── gas-info.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── gas-info-abi.json │ │ ├── gas-info-storage_slots.json │ │ └── gas-info.bin │ └── src │ └── main.sw ├── 12-contract-info ├── Forc.lock ├── Forc.toml ├── solidity │ └── Contract.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── contract-info-abi.json │ ├── contract-info-storage_slots.json │ └── contract-info.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── contract-info-abi.json │ │ ├── contract-info-storage_slots.json │ │ └── contract-info.bin │ └── src │ └── main.sw ├── 13-block-info ├── Forc.lock ├── Forc.toml ├── solidity │ └── Block.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── block-info-abi.json │ ├── block-info-storage_slots.json │ └── block-info.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── block-info-abi.json │ │ ├── block-info-storage_slots.json │ │ └── block-info.bin │ └── src │ └── main.sw ├── 14-transfer ├── Forc.lock ├── Forc.toml ├── solidity │ └── Transfer.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── debug │ ├── transfer-abi.json │ ├── transfer-storage_slots.json │ └── transfer.bin │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── transfer-abi.json │ │ ├── transfer-storage_slots.json │ │ └── transfer.bin │ └── src │ └── main.sw ├── 15-mint-tokens ├── Forc.lock ├── Forc.toml ├── solidity │ └── MintTokens.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── mint-tokens-abi.json │ │ ├── mint-tokens-storage_slots.json │ │ └── mint-tokens.bin │ └── src │ └── main.sw ├── 16-hashing ├── Forc.lock ├── Forc.toml ├── solidity │ └── Hashing.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── hashing-abi.json │ │ ├── hashing-storage_slots.json │ │ └── hashing.bin │ └── src │ └── main.sw ├── 17-ec-recover ├── Forc.lock ├── Forc.toml ├── solidity │ └── ECRecover.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── ec-recover-abi.json │ │ ├── ec-recover-storage_slots.json │ │ └── ec-recover.bin │ └── src │ └── main.sw ├── 18-reentrancy-guard ├── Forc.lock ├── Forc.toml ├── solidity │ └── Re-entrancy.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── re-entrancy-abi.json │ │ ├── re-entrancy-storage_slots.json │ │ └── re-entrancy.bin │ └── src │ ├── main.sw │ └── reentrancy.sw ├── 19-unsigned-integers ├── Forc.lock ├── Forc.toml ├── solidity │ └── UnsignedInts.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── unsigned-ints-abi.json │ │ ├── unsigned-ints-storage_slots.json │ │ └── unsigned-ints.bin │ └── src │ └── main.sw ├── 20-contract-calls ├── Forc.lock ├── Forc.toml ├── solidity │ └── ContractCalls.sol └── sway │ ├── Forc.lock │ ├── Forc.toml │ ├── fuel-toolchain.toml │ ├── out │ └── debug │ │ ├── contract-calls-abi.json │ │ ├── contract-calls-storage_slots.json │ │ └── contract-calls.bin │ └── src │ ├── interface.sw │ └── main.sw ├── LICENSE └── README.md /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | release: 9 | types: [published] 10 | 11 | env: 12 | RUST_VERSION: 1.68.2 13 | SOLC_CACHE_PATH: ${{ github.workspace }}/.solc_cache 14 | FUEL_CACHE_PATH: ${{ github.workspace }}/.fuel_cache 15 | 16 | jobs: 17 | build-contracts: 18 | runs-on: ubuntu-latest 19 | 20 | strategy: 21 | matrix: 22 | project: 23 | [ 24 | "01-hello-world", 25 | "02-counter", 26 | "03-logging", 27 | "04-storage", 28 | "05-conditional", 29 | "06-structs", 30 | "07-errors", 31 | "08-functions", 32 | "09-amounts", 33 | "10-message-info", 34 | "11-gas-info", 35 | "12-contract-info", 36 | "13-block-info", 37 | "14-transfer", 38 | "15-mint-tokens", 39 | "16-hashing", 40 | "17-ec-recover", 41 | "18-reentrancy-guard", 42 | "19-unsigned-integers", 43 | "20-contract-calls", 44 | ] 45 | 46 | steps: 47 | - name: Checkout repository 48 | uses: actions/checkout@v3 49 | 50 | - name: Setup solc cache 51 | uses: actions/cache@v2 52 | with: 53 | path: ${{ env.SOLC_CACHE_PATH }} 54 | key: solc-cache 55 | 56 | - name: Install Solidity Compiler 57 | if: steps.cache.outputs.cache-hit != 'true' 58 | run: | 59 | sudo add-apt-repository -y ppa:ethereum/ethereum 60 | sudo apt-get update 61 | sudo apt-get install -y solc 62 | mkdir -p ${{ env.SOLC_CACHE_PATH }} 63 | cp $(which solc) ${{ env.SOLC_CACHE_PATH }}/solc 64 | 65 | - name: Add solc to PATH 66 | run: echo "${{ env.SOLC_CACHE_PATH }}:${GITHUB_PATH}" >> $GITHUB_PATH 67 | 68 | - name: Install Rust toolchain 69 | uses: dtolnay/rust-toolchain@master 70 | with: 71 | toolchain: ${{ env.RUST_VERSION }} 72 | components: clippy, rustfmt 73 | 74 | - name: Init cache 75 | uses: Swatinem/rust-cache@v2 76 | 77 | - name: Setup fuel cache 78 | uses: actions/cache@v2 79 | with: 80 | path: ${{ env.FUEL_CACHE_PATH }} 81 | key: fuel-cache 82 | 83 | - name: Install Fuel toolchain 84 | if: steps.cache.outputs.cache-hit != 'true' 85 | run: | 86 | curl --proto '=https' --tlsv1.2 -sSf https://install.fuel.network/fuelup-init.sh | sh 87 | mkdir -p ${{ env.FUEL_CACHE_PATH }} 88 | cp -r $HOME/.fuelup/bin ${{ env.FUEL_CACHE_PATH }}/bin 89 | 90 | - name: Add fuel to PATH 91 | run: echo "${{ env.FUEL_CACHE_PATH }}/bin:${GITHUB_PATH}" >> $GITHUB_PATH 92 | 93 | - name: Build Sway 94 | run: | 95 | forc build --path ./${{ matrix.project }}/sway 96 | 97 | - name: Build Solidity 98 | run: | 99 | solc ./${{ matrix.project }}/solidity/*.sol 100 | -------------------------------------------------------------------------------- /01-hello-world/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "hello-world" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /01-hello-world/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /01-hello-world/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/01-hello-world/readme.md -------------------------------------------------------------------------------- /01-hello-world/solidity/HelloWorld.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.24; 4 | 5 | /// @title Hello World 6 | contract HelloWorld { 7 | /// @notice Returns 777 8 | uint public lucky_number = 777; 9 | } 10 | -------------------------------------------------------------------------------- /01-hello-world/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'hello-world' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /01-hello-world/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "hello-world" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /01-hello-world/sway/debug/hello-world-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "str[12]", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "get_greeting", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": [ 20 | { 21 | "name": "storage", 22 | "arguments": [ 23 | "read" 24 | ] 25 | } 26 | ] 27 | } 28 | ], 29 | "loggedTypes": [], 30 | "messagesTypes": [], 31 | "configurables": [] 32 | } -------------------------------------------------------------------------------- /01-hello-world/sway/debug/hello-world-storage_slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", 4 | "value": "48656c6c6f20576f726c64210000000000000000000000000000000000000000" 5 | } 6 | ] -------------------------------------------------------------------------------- /01-hello-world/sway/debug/hello-world.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/01-hello-world/sway/debug/hello-world.bin -------------------------------------------------------------------------------- /01-hello-world/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /01-hello-world/sway/out/debug/hello-world-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "u64", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "get_lucky_number", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": [ 20 | { 21 | "name": "storage", 22 | "arguments": [ 23 | "read" 24 | ] 25 | } 26 | ] 27 | } 28 | ], 29 | "loggedTypes": [], 30 | "messagesTypes": [], 31 | "configurables": [] 32 | } -------------------------------------------------------------------------------- /01-hello-world/sway/out/debug/hello-world-storage_slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", 4 | "value": "0000000000000008000000000000000000000000000000000000000000000000" 5 | } 6 | ] -------------------------------------------------------------------------------- /01-hello-world/sway/out/debug/hello-world.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/01-hello-world/sway/out/debug/hello-world.bin -------------------------------------------------------------------------------- /01-hello-world/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::*; 4 | 5 | abi HelloWorld { 6 | #[storage(read)] 7 | fn get_lucky_number() -> u64; 8 | } 9 | 10 | storage { 11 | // greeting: str = "Hello World!", 12 | lucky_number: u64 = 8, 13 | } 14 | 15 | impl HelloWorld for Contract { 16 | #[storage(read)] 17 | fn get_lucky_number() -> u64 { 18 | return storage.lucky_number.read() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /02-counter/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "counter" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /02-counter/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /02-counter/solidity/Counter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Count Tracker 5 | contract Counter { 6 | /// @notice Returns current count. 7 | /// @dev Initializes to zero implicitly. 8 | uint256 public count; 9 | 10 | /// @notice Increments the count. 11 | function increment() external { 12 | count += 1; 13 | } 14 | } -------------------------------------------------------------------------------- /02-counter/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'counter' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /02-counter/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "counter" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /02-counter/sway/debug/counter-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [], 19 | "name": "count", 20 | "output": { 21 | "name": "", 22 | "type": 1, 23 | "typeArguments": null 24 | }, 25 | "attributes": [ 26 | { 27 | "name": "storage", 28 | "arguments": [ 29 | "read" 30 | ] 31 | } 32 | ] 33 | }, 34 | { 35 | "inputs": [], 36 | "name": "increment", 37 | "output": { 38 | "name": "", 39 | "type": 0, 40 | "typeArguments": null 41 | }, 42 | "attributes": [ 43 | { 44 | "name": "storage", 45 | "arguments": [ 46 | "read", 47 | "write" 48 | ] 49 | } 50 | ] 51 | } 52 | ], 53 | "loggedTypes": [], 54 | "messagesTypes": [], 55 | "configurables": [] 56 | } -------------------------------------------------------------------------------- /02-counter/sway/debug/counter-storage_slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", 4 | "value": "0000000000000000000000000000000000000000000000000000000000000000" 5 | } 6 | ] -------------------------------------------------------------------------------- /02-counter/sway/debug/counter.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/02-counter/sway/debug/counter.bin -------------------------------------------------------------------------------- /02-counter/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /02-counter/sway/out/debug/counter-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [], 19 | "name": "count", 20 | "output": { 21 | "name": "", 22 | "type": 1, 23 | "typeArguments": null 24 | }, 25 | "attributes": [ 26 | { 27 | "name": "storage", 28 | "arguments": [ 29 | "read" 30 | ] 31 | } 32 | ] 33 | }, 34 | { 35 | "inputs": [], 36 | "name": "increment", 37 | "output": { 38 | "name": "", 39 | "type": 0, 40 | "typeArguments": null 41 | }, 42 | "attributes": [ 43 | { 44 | "name": "storage", 45 | "arguments": [ 46 | "read", 47 | "write" 48 | ] 49 | } 50 | ] 51 | } 52 | ], 53 | "loggedTypes": [], 54 | "messagesTypes": [], 55 | "configurables": [] 56 | } -------------------------------------------------------------------------------- /02-counter/sway/out/debug/counter-storage_slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", 4 | "value": "0000000000000000000000000000000000000000000000000000000000000000" 5 | } 6 | ] -------------------------------------------------------------------------------- /02-counter/sway/out/debug/counter.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/02-counter/sway/out/debug/counter.bin -------------------------------------------------------------------------------- /02-counter/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::*; 4 | 5 | storage { 6 | counter: u64 = 0, 7 | } 8 | 9 | abi Counter { 10 | #[storage(read, write)] 11 | fn increment(); 12 | 13 | #[storage(read)] 14 | fn count() -> u64; 15 | } 16 | 17 | impl Counter for Contract { 18 | #[storage(read)] 19 | fn count() -> u64 { 20 | return storage.counter.read(); 21 | } 22 | 23 | #[storage(read, write)] 24 | fn increment() { 25 | let incremented = storage.counter.read() + 1; 26 | storage.counter.write(incremented); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /03-logging/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "logging" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /03-logging/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /03-logging/solidity/Event.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Event Logger 5 | contract Event { 6 | /// @notice Logged by `logger()`. 7 | /// @param num Number to log. 8 | /// @param message Message to log. 9 | event Log(uint256 num, string message); 10 | 11 | /// @notice Logs `Log`. 12 | function logger() public { 13 | emit Log(42, "Hello World!"); 14 | } 15 | } -------------------------------------------------------------------------------- /03-logging/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'logging' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /03-logging/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "logging" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /03-logging/sway/debug/logging-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "str[12]", 12 | "components": null, 13 | "typeParameters": null 14 | }, 15 | { 16 | "typeId": 2, 17 | "type": "u64", 18 | "components": null, 19 | "typeParameters": null 20 | } 21 | ], 22 | "functions": [ 23 | { 24 | "inputs": [], 25 | "name": "logger", 26 | "output": { 27 | "name": "", 28 | "type": 0, 29 | "typeArguments": null 30 | }, 31 | "attributes": null 32 | } 33 | ], 34 | "loggedTypes": [ 35 | { 36 | "logId": 0, 37 | "loggedType": { 38 | "name": "", 39 | "type": 2, 40 | "typeArguments": null 41 | } 42 | }, 43 | { 44 | "logId": 1, 45 | "loggedType": { 46 | "name": "", 47 | "type": 1, 48 | "typeArguments": null 49 | } 50 | } 51 | ], 52 | "messagesTypes": [], 53 | "configurables": [] 54 | } -------------------------------------------------------------------------------- /03-logging/sway/debug/logging-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /03-logging/sway/debug/logging.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/03-logging/sway/debug/logging.bin -------------------------------------------------------------------------------- /03-logging/sway/out/debug/logging-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "str", 12 | "components": null, 13 | "typeParameters": null 14 | }, 15 | { 16 | "typeId": 2, 17 | "type": "u64", 18 | "components": null, 19 | "typeParameters": null 20 | } 21 | ], 22 | "functions": [ 23 | { 24 | "inputs": [], 25 | "name": "logger", 26 | "output": { 27 | "name": "", 28 | "type": 0, 29 | "typeArguments": null 30 | }, 31 | "attributes": null 32 | } 33 | ], 34 | "loggedTypes": [ 35 | { 36 | "logId": 0, 37 | "loggedType": { 38 | "name": "", 39 | "type": 2, 40 | "typeArguments": null 41 | } 42 | }, 43 | { 44 | "logId": 1, 45 | "loggedType": { 46 | "name": "", 47 | "type": 1, 48 | "typeArguments": null 49 | } 50 | } 51 | ], 52 | "messagesTypes": [], 53 | "configurables": [] 54 | } -------------------------------------------------------------------------------- /03-logging/sway/out/debug/logging-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /03-logging/sway/out/debug/logging.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/03-logging/sway/out/debug/logging.bin -------------------------------------------------------------------------------- /03-logging/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::logging::log; 4 | 5 | abi Event { 6 | fn logger(); 7 | } 8 | 9 | impl Event for Contract { 10 | fn logger() { 11 | log(42); 12 | log("Hello World!"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /04-storage/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "std" 7 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 8 | dependencies = ["core"] 9 | 10 | [[package]] 11 | name = "storage" 12 | source = "member" 13 | dependencies = ["std"] 14 | -------------------------------------------------------------------------------- /04-storage/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /04-storage/solidity/Storage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Storage Manager 5 | contract Storage { 6 | /// @notice Number variable. 7 | uint256 public number = 2; 8 | 9 | /// @notice String variable. 10 | /// @dev use `stringg` because `string` is a Solidity keyword. 11 | string public stringg = "Sol"; 12 | 13 | /// @notice Boolean varibale. 14 | bool public boolean = false; 15 | 16 | /// @notice HashMap maps number to address. 17 | mapping(uint => address) public map; 18 | 19 | /// @notice Arbitrary length storage array. 20 | uint256[] public array = [1,2,3]; 21 | 22 | /// @notice Internal Number. 23 | /// @dev No getter function is generated. 24 | uint256 internal internalNumber = 45; 25 | 26 | /// @notice Private Number. 27 | /// @dev No getter function is generated. 28 | /// Inheriting contracts MAY NOT override or deal with this value directly. 29 | uint256 private privateNumber = 55; 30 | 31 | /// @notice Returns storage variables. 32 | /// @dev The `view` keyword indicates it ONLY reads storage. 33 | function readStorage() public view returns ( 34 | uint256, 35 | string memory, 36 | bool, 37 | address, 38 | uint256, 39 | uint256, 40 | uint256 41 | ) { 42 | uint256 newNumber = number; 43 | string memory newString = stringg; 44 | bool newBoolean = boolean; 45 | address newAddress = map[1]; 46 | uint arrayNumber = array[0]; 47 | uint256 newInternalNumber = internalNumber; 48 | uint newPrivateNumber = privateNumber; 49 | 50 | return ( 51 | newNumber, 52 | newString, 53 | newBoolean, 54 | newAddress, 55 | arrayNumber, 56 | newInternalNumber, 57 | newPrivateNumber 58 | ); 59 | } 60 | 61 | /// @notice Updates storage variables. 62 | function updateStorage() public { 63 | number = 5; 64 | stringg = "evm"; 65 | boolean = true; 66 | address myAddress = 0x0101010101010101010101010101010101010101; 67 | map[1] = myAddress; 68 | array.push(4); 69 | internalNumber = 19; 70 | privateNumber = 20; 71 | } 72 | 73 | /// @notice Reads and Updates storage. 74 | function readUpdateStorage() public { 75 | number = number + 1; 76 | stringg = stringg; 77 | boolean = !boolean; 78 | map[2] = map[1]; 79 | array.push(array[0]); 80 | internalNumber = internalNumber + 1; 81 | privateNumber = privateNumber + 1; 82 | } 83 | 84 | /// @notice Does not interact with storage. 85 | function pureFunction (uint a, uint b) public pure returns (uint) { 86 | return a + b; 87 | } 88 | } -------------------------------------------------------------------------------- /04-storage/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'std' 7 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 8 | dependencies = ['core'] 9 | 10 | [[package]] 11 | name = 'storage' 12 | source = 'member' 13 | dependencies = ['std'] 14 | -------------------------------------------------------------------------------- /04-storage/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "storage" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /04-storage/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /04-storage/sway/out/debug/storage-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [ 19 | { 20 | "name": "a", 21 | "type": 1, 22 | "typeArguments": null 23 | }, 24 | { 25 | "name": "b", 26 | "type": 1, 27 | "typeArguments": null 28 | } 29 | ], 30 | "name": "pure_function", 31 | "output": { 32 | "name": "", 33 | "type": 1, 34 | "typeArguments": null 35 | }, 36 | "attributes": null 37 | }, 38 | { 39 | "inputs": [], 40 | "name": "read_and_update_storage", 41 | "output": { 42 | "name": "", 43 | "type": 0, 44 | "typeArguments": null 45 | }, 46 | "attributes": [ 47 | { 48 | "name": "storage", 49 | "arguments": [ 50 | "read", 51 | "write" 52 | ] 53 | } 54 | ] 55 | }, 56 | { 57 | "inputs": [], 58 | "name": "read_storage", 59 | "output": { 60 | "name": "", 61 | "type": 0, 62 | "typeArguments": null 63 | }, 64 | "attributes": [ 65 | { 66 | "name": "storage", 67 | "arguments": [ 68 | "read" 69 | ] 70 | } 71 | ] 72 | }, 73 | { 74 | "inputs": [], 75 | "name": "update_storage", 76 | "output": { 77 | "name": "", 78 | "type": 0, 79 | "typeArguments": null 80 | }, 81 | "attributes": [ 82 | { 83 | "name": "storage", 84 | "arguments": [ 85 | "write" 86 | ] 87 | } 88 | ] 89 | } 90 | ], 91 | "loggedTypes": [], 92 | "messagesTypes": [], 93 | "configurables": [] 94 | } -------------------------------------------------------------------------------- /04-storage/sway/out/debug/storage-storage_slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "de9090cb50e71c2588c773487d1da7066d0c719849a7e58dc8b6397a25c567c0", 4 | "value": "0000000000000000000000000000000000000000000000000000000000000000" 5 | }, 6 | { 7 | "key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", 8 | "value": "0000000000000000000000000000000000000000000000000000000000000000" 9 | } 10 | ] -------------------------------------------------------------------------------- /04-storage/sway/out/debug/storage.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/04-storage/sway/out/debug/storage.bin -------------------------------------------------------------------------------- /04-storage/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{ 4 | storage::storage_vec::*, 5 | hash::Hash, 6 | }; 7 | 8 | abi Storage { 9 | #[storage(read)] 10 | fn read_storage(); 11 | 12 | #[storage(write)] 13 | fn update_storage(); 14 | 15 | #[storage(read, write)] 16 | fn read_and_update_storage(); 17 | 18 | fn pure_function(a: u64, b: u64) -> u64; 19 | } 20 | 21 | storage { 22 | number: u64 = 0, 23 | boolean: bool = false, 24 | map: StorageMap = StorageMap {}, 25 | vector: StorageVec = StorageVec {}, 26 | } 27 | 28 | impl Storage for Contract { 29 | #[storage(read)] 30 | fn read_storage() { 31 | let number = storage.number; 32 | let boolean = storage.boolean; 33 | // will return an Option with either Some(value) or None 34 | let map_item = storage.map.get(1); 35 | // will return an Option with either Some(value) or None 36 | let vector_item_option = storage.vector.get(0); 37 | } 38 | 39 | #[storage(write)] 40 | fn update_storage() { 41 | storage.number.write(8); 42 | storage.boolean.write(true); 43 | 44 | let addr1 = Address::from(0x0101010101010101010101010101010101010101010101010101010101010101); 45 | storage.map.insert(1, addr1); 46 | 47 | // requires both read & write 48 | // storage.vector.push(5); 49 | } 50 | 51 | #[storage(read, write)] 52 | fn read_and_update_storage() { 53 | let incremented = storage.number.read() + 1; 54 | storage.number.write(incremented); 55 | storage.boolean.write(!storage.boolean.read()); 56 | 57 | // copy a storage map value to a new key 58 | let map_item = storage.map.get(1).read(); 59 | storage.map.insert(2, map_item); 60 | 61 | // add 5 to the end of the storageVec vector 62 | storage.vector.push(5); 63 | } 64 | 65 | fn pure_function(a: u64, b: u64) -> u64 { 66 | a + b 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /05-conditional/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "conditional" 3 | source = "member" 4 | dependencies = ["std"] 5 | 6 | [[package]] 7 | name = "core" 8 | source = "path+from-root-C3992B43B72ADB8C" 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /05-conditional/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /05-conditional/solidity/Conditional.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Conditional Control Flow 5 | contract Conditional { 6 | /// @notice Returns value based on the parameter's value. 7 | /// @param x Value to check. 8 | function useIf(uint256 x) public pure returns (uint256) { 9 | if (x < 5) { 10 | return 0; 11 | } else if (x < 10) { 12 | return 1; 13 | } else { 14 | return 2; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /05-conditional/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'conditional' 3 | source = 'member' 4 | dependencies = ['std'] 5 | 6 | [[package]] 7 | name = 'core' 8 | source = 'path+from-root-1AA1C8235B783A81' 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /05-conditional/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "conditional" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /05-conditional/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /05-conditional/sway/out/debug/conditional-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "u64", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [ 13 | { 14 | "name": "x", 15 | "type": 0, 16 | "typeArguments": null 17 | } 18 | ], 19 | "name": "use_if", 20 | "output": { 21 | "name": "", 22 | "type": 0, 23 | "typeArguments": null 24 | }, 25 | "attributes": null 26 | }, 27 | { 28 | "inputs": [ 29 | { 30 | "name": "x", 31 | "type": 0, 32 | "typeArguments": null 33 | } 34 | ], 35 | "name": "use_match", 36 | "output": { 37 | "name": "", 38 | "type": 0, 39 | "typeArguments": null 40 | }, 41 | "attributes": null 42 | } 43 | ], 44 | "loggedTypes": [], 45 | "messagesTypes": [], 46 | "configurables": [] 47 | } -------------------------------------------------------------------------------- /05-conditional/sway/out/debug/conditional-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /05-conditional/sway/out/debug/conditional.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/05-conditional/sway/out/debug/conditional.bin -------------------------------------------------------------------------------- /05-conditional/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi Conditional { 4 | fn use_if(x: u64) -> u64; 5 | 6 | fn use_match(x: u64) -> u64; 7 | } 8 | 9 | impl Conditional for Contract { 10 | fn use_if(x: u64) -> u64 { 11 | if x < 5 { 12 | return 0; 13 | } else if x < 10 { return 1; } else { return 2; } 14 | } 15 | 16 | fn use_match(x: u64) -> u64 { 17 | match x { 18 | 0 => 1, 19 | _ => 2, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /06-structs/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "std" 7 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 8 | dependencies = ["core"] 9 | 10 | [[package]] 11 | name = "sway" 12 | source = "member" 13 | dependencies = ["std"] 14 | -------------------------------------------------------------------------------- /06-structs/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /06-structs/solidity/structs.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.17; 3 | 4 | /// @title To-Do Manager 5 | contract Todos { 6 | /// @dev To-Do Data Structure. 7 | /// @param text To-Do text. 8 | /// @param completed True if completed. 9 | struct Todo { 10 | string text; 11 | bool completed; 12 | } 13 | 14 | /// @notice To-Do list. 15 | /// @dev This implicitly creates a getter that allows fetching by index. 16 | Todo[] public todos; 17 | 18 | /// @notice Create a new To-Do 19 | /// @param text To-Do text. 20 | function create(string calldata text) public { 21 | // 3 ways to initialize a struct 22 | // - calling it like a function 23 | todos.push(Todo(text, false)); 24 | 25 | // key value mapping 26 | todos.push(Todo({text: text, completed: false})); 27 | 28 | // initialize an empty struct and then update it 29 | Todo memory todo; 30 | todo.text = text; 31 | // todo.completed initialized to false 32 | 33 | todos.push(todo); 34 | } 35 | 36 | /// @notice Updates the text of a To-Do. 37 | /// @param index Index of the To-Do item. 38 | /// @param text New To-Do text. 39 | function updateText(uint index, string calldata text) public { 40 | Todo storage todo = todos[index]; 41 | todo.text = text; 42 | } 43 | 44 | /// @notice Toggles whether a given To-Do item is completed, by index. 45 | /// @param index Index at which the To-Do item is to be toggled. 46 | function toggleCompleted(uint index) public { 47 | Todo storage todo = todos[index]; 48 | todo.completed = !todo.completed; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /06-structs/sway/.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | target 3 | -------------------------------------------------------------------------------- /06-structs/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'std' 7 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 8 | dependencies = ['core'] 9 | 10 | [[package]] 11 | name = 'sway' 12 | source = 'member' 13 | dependencies = ['std'] 14 | -------------------------------------------------------------------------------- /06-structs/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Kin Chan"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "sway" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /06-structs/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::storage_vec::*; 4 | 5 | struct Todo { 6 | text: str[10], 7 | completed: bool, 8 | } 9 | 10 | impl Todo { 11 | fn update_text(ref mut self, text: str[10]) { 12 | self.text = text; 13 | } 14 | } 15 | 16 | storage { 17 | todos: StorageVec = StorageVec {}, 18 | } 19 | 20 | abi Todos { 21 | #[storage(read, write)] 22 | fn create(text: str[10]); 23 | 24 | #[storage(read)] 25 | fn get(index: u64) -> Todo; 26 | 27 | #[storage(read, write)] 28 | fn update_text(index: u64, text: str[10]); 29 | 30 | #[storage(read, write)] 31 | fn toggle_completed(index: u64); 32 | } 33 | 34 | impl Todos for Contract { 35 | #[storage(read, write)] 36 | fn create(text: str[10]) { 37 | let new_todo = Todo { 38 | text: text, 39 | completed: false, 40 | }; 41 | storage.todos.push(new_todo); 42 | } 43 | 44 | #[storage(read)] 45 | fn get(index: u64) -> Todo { 46 | storage.todos.get(index).unwrap().read() 47 | } 48 | 49 | #[storage(read, write)] 50 | fn update_text(index: u64, text: str[10]) { 51 | let mut todo = storage.todos.get(index).unwrap().read(); 52 | todo.update_text(text); 53 | storage.todos.set(index, todo); 54 | } 55 | 56 | #[storage(read, write)] 57 | fn toggle_completed(index: u64) { 58 | let mut todo = storage.todos.get(index).unwrap().read(); 59 | todo.completed = !todo.completed; 60 | storage.todos.set(index, todo); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /07-errors/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "errors" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /07-errors/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /07-errors/solidity/Errors.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Error Thrower 5 | contract Error { 6 | /// @notice Requires `i` is greater than 10 with error string. 7 | /// @param i Value to constrain. 8 | function testRequire(uint256 i) public pure { 9 | require(i > 10, "Input must be greater than 10"); 10 | } 11 | 12 | /// @notice Number less than ten error. 13 | /// @dev Recommended custom, dev-defined error for gas savings. 14 | /// @param i input number. 15 | error InputIsLessThanTen(uint256 i); 16 | 17 | /// @notice Reverts if `i` is less than or equal to 10 with error string. 18 | function testCustomRevert(uint256 i) public pure { 19 | if (i <= 10) { 20 | revert InputIsLessThanTen(i); 21 | } 22 | } 23 | 24 | /// @dev Not recommended error. 25 | /// @notice Reverts if `i` is less than or equal to 10 with error string. 26 | function testRevert(uint256 i) public pure { 27 | if (i <= 10) { 28 | revert("Input must be greater than 10"); 29 | } 30 | } 31 | 32 | /// @notice Asserts `i` is equal to 0 with Panic error. 33 | function testAssert(uint256 i) public pure { 34 | assert(i == 10); 35 | } 36 | } -------------------------------------------------------------------------------- /07-errors/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'errors' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /07-errors/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "errors" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /07-errors/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /07-errors/sway/out/debug/errors-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "enum InvalidError", 12 | "components": [ 13 | { 14 | "name": "InputIsLessThanTen", 15 | "type": 3, 16 | "typeArguments": null 17 | } 18 | ], 19 | "typeParameters": null 20 | }, 21 | { 22 | "typeId": 2, 23 | "type": "str", 24 | "components": null, 25 | "typeParameters": null 26 | }, 27 | { 28 | "typeId": 3, 29 | "type": "u64", 30 | "components": null, 31 | "typeParameters": null 32 | } 33 | ], 34 | "functions": [ 35 | { 36 | "inputs": [ 37 | { 38 | "name": "i", 39 | "type": 3, 40 | "typeArguments": null 41 | } 42 | ], 43 | "name": "test_assert", 44 | "output": { 45 | "name": "", 46 | "type": 0, 47 | "typeArguments": null 48 | }, 49 | "attributes": null 50 | }, 51 | { 52 | "inputs": [ 53 | { 54 | "name": "i", 55 | "type": 3, 56 | "typeArguments": null 57 | } 58 | ], 59 | "name": "test_custom_require", 60 | "output": { 61 | "name": "", 62 | "type": 0, 63 | "typeArguments": null 64 | }, 65 | "attributes": null 66 | }, 67 | { 68 | "inputs": [ 69 | { 70 | "name": "i", 71 | "type": 3, 72 | "typeArguments": null 73 | } 74 | ], 75 | "name": "test_require", 76 | "output": { 77 | "name": "", 78 | "type": 0, 79 | "typeArguments": null 80 | }, 81 | "attributes": null 82 | }, 83 | { 84 | "inputs": [ 85 | { 86 | "name": "i", 87 | "type": 3, 88 | "typeArguments": null 89 | } 90 | ], 91 | "name": "test_revert", 92 | "output": { 93 | "name": "", 94 | "type": 0, 95 | "typeArguments": null 96 | }, 97 | "attributes": null 98 | } 99 | ], 100 | "loggedTypes": [ 101 | { 102 | "logId": 0, 103 | "loggedType": { 104 | "name": "", 105 | "type": 1, 106 | "typeArguments": [] 107 | } 108 | }, 109 | { 110 | "logId": 1, 111 | "loggedType": { 112 | "name": "", 113 | "type": 2, 114 | "typeArguments": null 115 | } 116 | } 117 | ], 118 | "messagesTypes": [], 119 | "configurables": [] 120 | } -------------------------------------------------------------------------------- /07-errors/sway/out/debug/errors-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /07-errors/sway/out/debug/errors.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/07-errors/sway/out/debug/errors.bin -------------------------------------------------------------------------------- /07-errors/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi Errors { 4 | fn test_require(i: u64); 5 | 6 | fn test_custom_require(i: u64); 7 | 8 | fn test_revert(i: u64); 9 | 10 | fn test_assert(i: u64); 11 | } 12 | 13 | enum InvalidError { 14 | InputIsLessThanTen: u64, 15 | } 16 | 17 | impl Errors for Contract { 18 | // Recommended custom, dev-defined require error for gas savings 19 | fn test_custom_require(i: u64) { 20 | require(i < 10, InvalidError::InputIsLessThanTen(i)); 21 | } 22 | 23 | // Not recommended for require 24 | fn test_require(i: u64) { 25 | require(i < 10, "Input must be greater than ten"); 26 | } 27 | 28 | fn test_revert(i: u64) { 29 | if (i <= 10) { 30 | revert(i); 31 | } 32 | } 33 | 34 | fn test_assert(i: u64) { 35 | assert(i == 10); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /08-functions/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "functions" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /08-functions/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /08-functions/solidity/Functions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | // Only callable interanlly, reads and writes storage. 5 | function freeInternalFunction() { 6 | assembly { sstore(0, sload(0)) } 7 | } 8 | 9 | // Only callable internally, does not interact with storage. 10 | function freeInternalPureFunction() pure {} 11 | 12 | /// @title Functions 13 | contract Functions { 14 | /// @dev Publicly callable function. Calls internal free function. 15 | /// MAY be called within the same contract. 16 | function publicFunction() public { 17 | freeInternalFunction(); 18 | } 19 | 20 | /// @dev Internally callable function. MAY be called within the same contract. 21 | function internalFunction() internal pure {} 22 | 23 | /// @dev Externally callable function. Calls internal contract function. 24 | /// MAY NOT be called within the same contract. 25 | function externalFunction() external pure { 26 | internalFunction(); 27 | } 28 | 29 | /// @dev Publicly callable function. 30 | /// @param x Input value. 31 | /// @param y Output value. 32 | function pureFunction(uint256 x) public pure returns (uint256 y) { 33 | // can only call other pure functions 34 | freeInternalPureFunction(); 35 | return x; 36 | } 37 | 38 | /// @dev Private function. MAY be called within the same contract. 39 | /// MAY NOT be called by inheriting contracts. 40 | function privateFunction() private pure returns (bool) { 41 | return true; 42 | } 43 | } -------------------------------------------------------------------------------- /08-functions/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'functions' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /08-functions/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "functions" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /08-functions/sway/debug/functions-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [], 19 | "name": "public_function", 20 | "output": { 21 | "name": "", 22 | "type": 0, 23 | "typeArguments": null 24 | }, 25 | "attributes": null 26 | }, 27 | { 28 | "inputs": [ 29 | { 30 | "name": "a", 31 | "type": 1, 32 | "typeArguments": null 33 | }, 34 | { 35 | "name": "b", 36 | "type": 1, 37 | "typeArguments": null 38 | } 39 | ], 40 | "name": "use_private_function", 41 | "output": { 42 | "name": "", 43 | "type": 1, 44 | "typeArguments": null 45 | }, 46 | "attributes": null 47 | } 48 | ], 49 | "loggedTypes": [], 50 | "messagesTypes": [], 51 | "configurables": [] 52 | } -------------------------------------------------------------------------------- /08-functions/sway/debug/functions-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /08-functions/sway/debug/functions.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/08-functions/sway/debug/functions.bin -------------------------------------------------------------------------------- /08-functions/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /08-functions/sway/out/debug/functions-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [], 19 | "name": "public_function", 20 | "output": { 21 | "name": "", 22 | "type": 0, 23 | "typeArguments": null 24 | }, 25 | "attributes": null 26 | }, 27 | { 28 | "inputs": [ 29 | { 30 | "name": "a", 31 | "type": 1, 32 | "typeArguments": null 33 | }, 34 | { 35 | "name": "b", 36 | "type": 1, 37 | "typeArguments": null 38 | } 39 | ], 40 | "name": "use_private_function", 41 | "output": { 42 | "name": "", 43 | "type": 1, 44 | "typeArguments": null 45 | }, 46 | "attributes": null 47 | } 48 | ], 49 | "loggedTypes": [], 50 | "messagesTypes": [], 51 | "configurables": [] 52 | } -------------------------------------------------------------------------------- /08-functions/sway/out/debug/functions-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /08-functions/sway/out/debug/functions.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/08-functions/sway/out/debug/functions.bin -------------------------------------------------------------------------------- /08-functions/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | // all functions in the abi can be called externally 4 | abi Functions { 5 | fn public_function(); 6 | 7 | fn use_private_function(a: u64, b: u64) -> u64; 8 | } 9 | 10 | // this function can only be called internally 11 | fn private_function(a: u64, b: u64) -> u64 { 12 | a + b 13 | } 14 | 15 | impl Functions for Contract { 16 | fn public_function() { 17 | // do something 18 | } 19 | 20 | fn use_private_function(a: u64, b: u64) -> u64 { 21 | private_function(a, b) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /09-amounts/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "amounts" 3 | source = "member" 4 | dependencies = ["std"] 5 | 6 | [[package]] 7 | name = "core" 8 | source = "path+from-root-C3992B43B72ADB8C" 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /09-amounts/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /09-amounts/solidity/Amounts.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Amounts 5 | contract Amounts { 6 | /// @notice One Wei (smallest unit of Ether). 7 | uint public oneWei = 1 wei; 8 | 9 | /// @notice True, as `1 wei` is `1`. 10 | bool public isOneWei = 1 wei == 1; 11 | 12 | /// @notice One Giga-Wei (10 ** 9 Wei), 13 | uint public oneGwei = 1 gwei; 14 | 15 | /// @notice True, as `1 gwei` is `1e19` or `1_000_000_000`. 16 | bool public isOneGwei = 1 gwei == 1e9; 17 | 18 | /// @notice One Ether 19 | uint public oneEther = 1 ether; 20 | 21 | /// @notice True, as `1 ether` is `1e18` or `1_000_000_000_000_000_000`. 22 | bool public isOneEther = 1 ether == 1e18; 23 | } -------------------------------------------------------------------------------- /09-amounts/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'amounts' 3 | source = 'member' 4 | dependencies = ['std'] 5 | 6 | [[package]] 7 | name = 'core' 8 | source = 'path+from-root-1AA1C8235B783A81' 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /09-amounts/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "amounts" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /09-amounts/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /09-amounts/sway/out/debug/amounts-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "amounts", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": null 20 | } 21 | ], 22 | "loggedTypes": [], 23 | "messagesTypes": [], 24 | "configurables": [] 25 | } -------------------------------------------------------------------------------- /09-amounts/sway/out/debug/amounts-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /09-amounts/sway/out/debug/amounts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/09-amounts/sway/out/debug/amounts.bin -------------------------------------------------------------------------------- /09-amounts/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::constants::BASE_ASSET_ID; 4 | 5 | abi Amounts { 6 | fn amounts(); 7 | } 8 | 9 | impl Amounts for Contract { 10 | fn amounts() { 11 | let one_gwei = 1; 12 | let one_ether = 1_000_000_000; 13 | let base_asset = BASE_ASSET_ID; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /10-message-info/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "message-info" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /10-message-info/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /10-message-info/solidity/Message.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Message Information 5 | /// @notice Expoes all `msg.*` methods. 6 | contract MessageInfo { 7 | /// @notice Returns the address of the caller. 8 | /// @dev Considered `view` as it must read the global state (caller). 9 | function getSender() public view returns (address) { 10 | return msg.sender; 11 | } 12 | 13 | /// @notice Returns the value of the call in Wei. 14 | /// @dev Considered `payable` as receiving Ether updates the global state. 15 | function getAmount() public payable returns (uint256) { 16 | return msg.value; 17 | } 18 | 19 | /// @notice Returns the four byte function selector. 20 | /// @dev Considered pure as only the calldata is read. 21 | function getSig() public pure returns (bytes4) { 22 | return msg.sig; 23 | } 24 | 25 | /// @notice Returns the full calldata. 26 | /// @dev Considered pure as only the calldata is read. 27 | function getData() public pure returns (bytes memory) { 28 | return msg.data; 29 | } 30 | } -------------------------------------------------------------------------------- /10-message-info/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'message-info' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /10-message-info/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "message-info" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /10-message-info/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /10-message-info/sway/out/debug/message-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "b256", 6 | "components": null, 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "enum Identity", 12 | "components": [ 13 | { 14 | "name": "Address", 15 | "type": 2, 16 | "typeArguments": null 17 | }, 18 | { 19 | "name": "ContractId", 20 | "type": 4, 21 | "typeArguments": null 22 | } 23 | ], 24 | "typeParameters": null 25 | }, 26 | { 27 | "typeId": 2, 28 | "type": "struct Address", 29 | "components": [ 30 | { 31 | "name": "value", 32 | "type": 0, 33 | "typeArguments": null 34 | } 35 | ], 36 | "typeParameters": null 37 | }, 38 | { 39 | "typeId": 3, 40 | "type": "struct AssetId", 41 | "components": [ 42 | { 43 | "name": "value", 44 | "type": 0, 45 | "typeArguments": null 46 | } 47 | ], 48 | "typeParameters": null 49 | }, 50 | { 51 | "typeId": 4, 52 | "type": "struct ContractId", 53 | "components": [ 54 | { 55 | "name": "value", 56 | "type": 0, 57 | "typeArguments": null 58 | } 59 | ], 60 | "typeParameters": null 61 | }, 62 | { 63 | "typeId": 5, 64 | "type": "u64", 65 | "components": null, 66 | "typeParameters": null 67 | } 68 | ], 69 | "functions": [ 70 | { 71 | "inputs": [], 72 | "name": "get_amount", 73 | "output": { 74 | "name": "", 75 | "type": 5, 76 | "typeArguments": null 77 | }, 78 | "attributes": [ 79 | { 80 | "name": "payable", 81 | "arguments": [] 82 | } 83 | ] 84 | }, 85 | { 86 | "inputs": [], 87 | "name": "get_asset_id", 88 | "output": { 89 | "name": "", 90 | "type": 3, 91 | "typeArguments": null 92 | }, 93 | "attributes": [ 94 | { 95 | "name": "payable", 96 | "arguments": [] 97 | } 98 | ] 99 | }, 100 | { 101 | "inputs": [], 102 | "name": "get_sender", 103 | "output": { 104 | "name": "", 105 | "type": 1, 106 | "typeArguments": null 107 | }, 108 | "attributes": null 109 | } 110 | ], 111 | "loggedTypes": [], 112 | "messagesTypes": [], 113 | "configurables": [] 114 | } -------------------------------------------------------------------------------- /10-message-info/sway/out/debug/message-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /10-message-info/sway/out/debug/message-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/10-message-info/sway/out/debug/message-info.bin -------------------------------------------------------------------------------- /10-message-info/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{auth::{AuthError, msg_sender}, call_frames::msg_asset_id, context::msg_amount}; 4 | 5 | abi MessageInfo { 6 | fn get_sender() -> Identity; 7 | 8 | #[payable] 9 | fn get_amount() -> u64; 10 | 11 | #[payable] 12 | fn get_asset_id() -> AssetId; 13 | } 14 | 15 | impl MessageInfo for Contract { 16 | // returns the identity of the sender 17 | fn get_sender() -> Identity { 18 | msg_sender().unwrap() 19 | } 20 | 21 | // returns the amount sent (can be any asset) 22 | #[payable] 23 | fn get_amount() -> u64 { 24 | msg_amount() 25 | } 26 | 27 | // returns the asset id of the asset sent 28 | #[payable] 29 | fn get_asset_id() -> AssetId { 30 | msg_asset_id() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /10.5.0: -------------------------------------------------------------------------------- 1 | Unknown command: "notice" 2 | 3 | To see a list of supported npm commands, run: 4 | npm help 5 | -------------------------------------------------------------------------------- /11-gas-info/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "gas-info" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /11-gas-info/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /11-gas-info/solidity/Gas.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Gas Information 5 | contract GasInfo { 6 | /// @notice Returns transaction gas price. 7 | function getGasPrice() public view returns (uint256) { 8 | return tx.gasprice; 9 | } 10 | 11 | /// @notice Returns remaining gas. 12 | function getGas() public view returns (uint256) { 13 | return gasleft(); 14 | } 15 | } -------------------------------------------------------------------------------- /11-gas-info/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'gas-info' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /11-gas-info/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "gas-info" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /11-gas-info/sway/debug/gas-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "u64", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "get_tx_gas_limit", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": null 20 | }, 21 | { 22 | "inputs": [], 23 | "name": "get_tx_gas_price", 24 | "output": { 25 | "name": "", 26 | "type": 0, 27 | "typeArguments": null 28 | }, 29 | "attributes": null 30 | } 31 | ], 32 | "loggedTypes": [], 33 | "messagesTypes": [], 34 | "configurables": [] 35 | } -------------------------------------------------------------------------------- /11-gas-info/sway/debug/gas-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /11-gas-info/sway/debug/gas-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/11-gas-info/sway/debug/gas-info.bin -------------------------------------------------------------------------------- /11-gas-info/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /11-gas-info/sway/out/debug/gas-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "u64", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "get_script_gas_limit", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": null 20 | }, 21 | { 22 | "inputs": [], 23 | "name": "get_tx_gas_price", 24 | "output": { 25 | "name": "", 26 | "type": 0, 27 | "typeArguments": null 28 | }, 29 | "attributes": null 30 | } 31 | ], 32 | "loggedTypes": [], 33 | "messagesTypes": [], 34 | "configurables": [] 35 | } -------------------------------------------------------------------------------- /11-gas-info/sway/out/debug/gas-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /11-gas-info/sway/out/debug/gas-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/11-gas-info/sway/out/debug/gas-info.bin -------------------------------------------------------------------------------- /11-gas-info/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::tx::{script_gas_limit, tx_gas_price}; 4 | 5 | abi GasInfo { 6 | fn get_tx_gas_price() -> u64; 7 | fn get_script_gas_limit() -> u64; 8 | } 9 | 10 | impl GasInfo for Contract { 11 | // Get the transaction gas price 12 | fn get_tx_gas_price() -> u64 { 13 | tx_gas_price().unwrap() 14 | } 15 | 16 | // Get the gas limit for the transaction 17 | fn get_script_gas_limit() -> u64 { 18 | script_gas_limit() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /12-contract-info/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "contract-info" 3 | source = "member" 4 | dependencies = ["std"] 5 | 6 | [[package]] 7 | name = "core" 8 | source = "path+from-root-C3992B43B72ADB8C" 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /12-contract-info/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /12-contract-info/solidity/Contract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Contract Information 5 | contract ContractInfo { 6 | /// @notice Get contract address. 7 | function getContractAddress() public view returns (address) { 8 | return address(this); 9 | } 10 | 11 | /// @notice Get contract balance. 12 | function getContractBalance() public view returns (uint256) { 13 | return address(this).balance; 14 | } 15 | } -------------------------------------------------------------------------------- /12-contract-info/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'contract-info' 3 | source = 'member' 4 | dependencies = ['std'] 5 | 6 | [[package]] 7 | name = 'core' 8 | source = 'path+from-root-1AA1C8235B783A81' 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /12-contract-info/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract-info" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /12-contract-info/sway/debug/contract-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "b256", 6 | "components": null, 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "struct ContractId", 12 | "components": [ 13 | { 14 | "name": "value", 15 | "type": 0, 16 | "typeArguments": null 17 | } 18 | ], 19 | "typeParameters": null 20 | }, 21 | { 22 | "typeId": 2, 23 | "type": "u64", 24 | "components": null, 25 | "typeParameters": null 26 | } 27 | ], 28 | "functions": [ 29 | { 30 | "inputs": [ 31 | { 32 | "name": "asset", 33 | "type": 1, 34 | "typeArguments": null 35 | } 36 | ], 37 | "name": "get_contract_balance", 38 | "output": { 39 | "name": "", 40 | "type": 2, 41 | "typeArguments": null 42 | }, 43 | "attributes": null 44 | }, 45 | { 46 | "inputs": [], 47 | "name": "get_contract_id", 48 | "output": { 49 | "name": "", 50 | "type": 1, 51 | "typeArguments": null 52 | }, 53 | "attributes": null 54 | } 55 | ], 56 | "loggedTypes": [], 57 | "messagesTypes": [], 58 | "configurables": [] 59 | } -------------------------------------------------------------------------------- /12-contract-info/sway/debug/contract-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /12-contract-info/sway/debug/contract-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/12-contract-info/sway/debug/contract-info.bin -------------------------------------------------------------------------------- /12-contract-info/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /12-contract-info/sway/out/debug/contract-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "b256", 6 | "components": null, 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "struct AssetId", 12 | "components": [ 13 | { 14 | "name": "value", 15 | "type": 0, 16 | "typeArguments": null 17 | } 18 | ], 19 | "typeParameters": null 20 | }, 21 | { 22 | "typeId": 2, 23 | "type": "struct ContractId", 24 | "components": [ 25 | { 26 | "name": "value", 27 | "type": 0, 28 | "typeArguments": null 29 | } 30 | ], 31 | "typeParameters": null 32 | }, 33 | { 34 | "typeId": 3, 35 | "type": "u64", 36 | "components": null, 37 | "typeParameters": null 38 | } 39 | ], 40 | "functions": [ 41 | { 42 | "inputs": [ 43 | { 44 | "name": "asset", 45 | "type": 1, 46 | "typeArguments": null 47 | } 48 | ], 49 | "name": "get_contract_balance", 50 | "output": { 51 | "name": "", 52 | "type": 3, 53 | "typeArguments": null 54 | }, 55 | "attributes": null 56 | }, 57 | { 58 | "inputs": [], 59 | "name": "get_contract_id", 60 | "output": { 61 | "name": "", 62 | "type": 2, 63 | "typeArguments": null 64 | }, 65 | "attributes": null 66 | } 67 | ], 68 | "loggedTypes": [], 69 | "messagesTypes": [], 70 | "configurables": [] 71 | } -------------------------------------------------------------------------------- /12-contract-info/sway/out/debug/contract-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /12-contract-info/sway/out/debug/contract-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/12-contract-info/sway/out/debug/contract-info.bin -------------------------------------------------------------------------------- /12-contract-info/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{call_frames::contract_id, context::this_balance}; 4 | 5 | abi ContractInfo { 6 | fn get_contract_id() -> ContractId; 7 | 8 | fn get_contract_balance(asset: AssetId) -> u64; 9 | } 10 | 11 | impl ContractInfo for Contract { 12 | fn get_contract_id() -> ContractId { 13 | contract_id() 14 | } 15 | 16 | fn get_contract_balance(asset: AssetId) -> u64 { 17 | this_balance(asset) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /13-block-info/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "block-info" 3 | source = "member" 4 | dependencies = ["std"] 5 | 6 | [[package]] 7 | name = "core" 8 | source = "path+from-root-C3992B43B72ADB8C" 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /13-block-info/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /13-block-info/solidity/Block.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Block Information 5 | /// @notice Some block information is ommitted for comparasion to Sway. 6 | contract BlockInfo { 7 | /// @notice Gets block hash of a given block. 8 | /// @param blockNumber Block number for which the hash should be returned. 9 | function getBlockHash(uint256 blockNumber) public view returns (bytes32) { 10 | return blockhash(blockNumber); 11 | } 12 | 13 | /// @notice Gets current block number. 14 | function getBlockNumber() public view returns (uint){ 15 | return block.number; 16 | } 17 | 18 | /// @notice Gets current block timestamp. 19 | function getBlockTimestamp() public view returns (uint){ 20 | return block.timestamp; 21 | } 22 | } -------------------------------------------------------------------------------- /13-block-info/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'block-info' 3 | source = 'member' 4 | dependencies = ['std'] 5 | 6 | [[package]] 7 | name = 'core' 8 | source = 'path+from-root-1AA1C8235B783A81' 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /13-block-info/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "block-info" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /13-block-info/sway/debug/block-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "u64", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "get_block_height", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": null 20 | }, 21 | { 22 | "inputs": [], 23 | "name": "get_timestamp", 24 | "output": { 25 | "name": "", 26 | "type": 0, 27 | "typeArguments": null 28 | }, 29 | "attributes": null 30 | }, 31 | { 32 | "inputs": [], 33 | "name": "get_timestamp_of_block", 34 | "output": { 35 | "name": "", 36 | "type": 0, 37 | "typeArguments": null 38 | }, 39 | "attributes": null 40 | } 41 | ], 42 | "loggedTypes": [], 43 | "messagesTypes": [], 44 | "configurables": [] 45 | } -------------------------------------------------------------------------------- /13-block-info/sway/debug/block-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /13-block-info/sway/debug/block-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/13-block-info/sway/debug/block-info.bin -------------------------------------------------------------------------------- /13-block-info/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /13-block-info/sway/out/debug/block-info-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "u32", 6 | "components": null, 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [], 19 | "name": "get_block_height", 20 | "output": { 21 | "name": "", 22 | "type": 0, 23 | "typeArguments": null 24 | }, 25 | "attributes": null 26 | }, 27 | { 28 | "inputs": [], 29 | "name": "get_timestamp", 30 | "output": { 31 | "name": "", 32 | "type": 1, 33 | "typeArguments": null 34 | }, 35 | "attributes": null 36 | }, 37 | { 38 | "inputs": [], 39 | "name": "get_timestamp_of_block", 40 | "output": { 41 | "name": "", 42 | "type": 1, 43 | "typeArguments": null 44 | }, 45 | "attributes": null 46 | } 47 | ], 48 | "loggedTypes": [], 49 | "messagesTypes": [], 50 | "configurables": [] 51 | } -------------------------------------------------------------------------------- /13-block-info/sway/out/debug/block-info-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /13-block-info/sway/out/debug/block-info.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/13-block-info/sway/out/debug/block-info.bin -------------------------------------------------------------------------------- /13-block-info/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{block::{height, timestamp, timestamp_of_block}}; 4 | 5 | abi BlockInfo { 6 | fn get_block_height() -> u32; 7 | 8 | fn get_timestamp() -> u64; 9 | 10 | fn get_timestamp_of_block() -> u64; 11 | } 12 | 13 | impl BlockInfo for Contract { 14 | fn get_block_height() -> u32 { 15 | height() 16 | } 17 | 18 | fn get_timestamp() -> u64 { 19 | timestamp() 20 | } 21 | 22 | fn get_timestamp_of_block() -> u64 { 23 | timestamp_of_block(12345) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /14-transfer/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "std" 7 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 8 | dependencies = ["core"] 9 | 10 | [[package]] 11 | name = "transfer" 12 | source = "member" 13 | dependencies = ["std"] 14 | -------------------------------------------------------------------------------- /14-transfer/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /14-transfer/solidity/Transfer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Transferooor 5 | contract Transfer { 6 | /// @notice Send via `address.transfer` method. 7 | /// @dev DOES NOT send enough gas to reenter. 8 | function sendWithTransfer(address payable _to) public payable { 9 | _to.transfer(msg.value); 10 | } 11 | 12 | /// @notice Send via `address.send` method. 13 | /// @dev DOES NOT send enough gas to reenter. 14 | function sendWithSend(address payable _to) public payable { 15 | bool sent = _to.send(msg.value); 16 | require(sent, "Failed to send Ether"); 17 | } 18 | 19 | /// @notice Send via `address.call` method. 20 | /// @dev RECOMMENDED method for transfers. 21 | function sendWithCall(address payable _to) public payable { 22 | (bool sent, ) = _to.call{value: msg.value}(""); 23 | require(sent, "Failed to send Ether"); 24 | } 25 | } -------------------------------------------------------------------------------- /14-transfer/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'std' 7 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 8 | dependencies = ['core'] 9 | 10 | [[package]] 11 | name = 'transfer' 12 | source = 'member' 13 | dependencies = ['std'] 14 | -------------------------------------------------------------------------------- /14-transfer/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "transfer" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /14-transfer/sway/debug/transfer-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "b256", 12 | "components": null, 13 | "typeParameters": null 14 | }, 15 | { 16 | "typeId": 2, 17 | "type": "enum Identity", 18 | "components": [ 19 | { 20 | "name": "Address", 21 | "type": 3, 22 | "typeArguments": null 23 | }, 24 | { 25 | "name": "ContractId", 26 | "type": 4, 27 | "typeArguments": null 28 | } 29 | ], 30 | "typeParameters": null 31 | }, 32 | { 33 | "typeId": 3, 34 | "type": "struct Address", 35 | "components": [ 36 | { 37 | "name": "value", 38 | "type": 1, 39 | "typeArguments": null 40 | } 41 | ], 42 | "typeParameters": null 43 | }, 44 | { 45 | "typeId": 4, 46 | "type": "struct ContractId", 47 | "components": [ 48 | { 49 | "name": "value", 50 | "type": 1, 51 | "typeArguments": null 52 | } 53 | ], 54 | "typeParameters": null 55 | } 56 | ], 57 | "functions": [ 58 | { 59 | "inputs": [ 60 | { 61 | "name": "receiver", 62 | "type": 3, 63 | "typeArguments": null 64 | } 65 | ], 66 | "name": "transfer_to_address", 67 | "output": { 68 | "name": "", 69 | "type": 0, 70 | "typeArguments": null 71 | }, 72 | "attributes": null 73 | }, 74 | { 75 | "inputs": [ 76 | { 77 | "name": "receiver", 78 | "type": 2, 79 | "typeArguments": null 80 | } 81 | ], 82 | "name": "transfer_to_address_or_contract", 83 | "output": { 84 | "name": "", 85 | "type": 0, 86 | "typeArguments": null 87 | }, 88 | "attributes": null 89 | }, 90 | { 91 | "inputs": [ 92 | { 93 | "name": "receiver", 94 | "type": 4, 95 | "typeArguments": null 96 | } 97 | ], 98 | "name": "transfer_to_contract", 99 | "output": { 100 | "name": "", 101 | "type": 0, 102 | "typeArguments": null 103 | }, 104 | "attributes": null 105 | } 106 | ], 107 | "loggedTypes": [], 108 | "messagesTypes": [], 109 | "configurables": [] 110 | } -------------------------------------------------------------------------------- /14-transfer/sway/debug/transfer-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /14-transfer/sway/debug/transfer.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/14-transfer/sway/debug/transfer.bin -------------------------------------------------------------------------------- /14-transfer/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /14-transfer/sway/out/debug/transfer-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "b256", 12 | "components": null, 13 | "typeParameters": null 14 | }, 15 | { 16 | "typeId": 2, 17 | "type": "enum Identity", 18 | "components": [ 19 | { 20 | "name": "Address", 21 | "type": 3, 22 | "typeArguments": null 23 | }, 24 | { 25 | "name": "ContractId", 26 | "type": 4, 27 | "typeArguments": null 28 | } 29 | ], 30 | "typeParameters": null 31 | }, 32 | { 33 | "typeId": 3, 34 | "type": "struct Address", 35 | "components": [ 36 | { 37 | "name": "value", 38 | "type": 1, 39 | "typeArguments": null 40 | } 41 | ], 42 | "typeParameters": null 43 | }, 44 | { 45 | "typeId": 4, 46 | "type": "struct ContractId", 47 | "components": [ 48 | { 49 | "name": "value", 50 | "type": 1, 51 | "typeArguments": null 52 | } 53 | ], 54 | "typeParameters": null 55 | } 56 | ], 57 | "functions": [ 58 | { 59 | "inputs": [ 60 | { 61 | "name": "receiver", 62 | "type": 3, 63 | "typeArguments": null 64 | } 65 | ], 66 | "name": "transfer_to_address", 67 | "output": { 68 | "name": "", 69 | "type": 0, 70 | "typeArguments": null 71 | }, 72 | "attributes": null 73 | }, 74 | { 75 | "inputs": [ 76 | { 77 | "name": "receiver", 78 | "type": 2, 79 | "typeArguments": null 80 | } 81 | ], 82 | "name": "transfer_to_address_or_contract", 83 | "output": { 84 | "name": "", 85 | "type": 0, 86 | "typeArguments": null 87 | }, 88 | "attributes": null 89 | }, 90 | { 91 | "inputs": [ 92 | { 93 | "name": "receiver", 94 | "type": 4, 95 | "typeArguments": null 96 | } 97 | ], 98 | "name": "transfer_to_contract", 99 | "output": { 100 | "name": "", 101 | "type": 0, 102 | "typeArguments": null 103 | }, 104 | "attributes": null 105 | } 106 | ], 107 | "loggedTypes": [], 108 | "messagesTypes": [], 109 | "configurables": [] 110 | } -------------------------------------------------------------------------------- /14-transfer/sway/out/debug/transfer-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /14-transfer/sway/out/debug/transfer.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/14-transfer/sway/out/debug/transfer.bin -------------------------------------------------------------------------------- /14-transfer/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{ 4 | constants::BASE_ASSET_ID, 5 | asset::{ 6 | transfer, 7 | force_transfer_to_contract, 8 | transfer_to_address, 9 | }, 10 | }; 11 | 12 | abi Transfer { 13 | fn transfer_to_address_or_contract(receiver: Identity); 14 | 15 | fn transfer_to_address(receiver: Address); 16 | 17 | fn transfer_to_contract(receiver: ContractId); 18 | } 19 | 20 | impl Transfer for Contract { 21 | fn transfer_to_address_or_contract(receiver: Identity) { 22 | transfer(receiver, BASE_ASSET_ID, 1); 23 | } 24 | 25 | fn transfer_to_address(receiver: Address) { 26 | transfer_to_address(receiver, BASE_ASSET_ID, 1); 27 | } 28 | 29 | fn transfer_to_contract(receiver: ContractId) { 30 | force_transfer_to_contract(receiver, BASE_ASSET_ID, 1); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /15-mint-tokens/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "mint-tokens" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /15-mint-tokens/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /15-mint-tokens/solidity/MintTokens.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title ERC20 Token 5 | contract MyToken { 6 | /// @notice Transfer Error. 7 | /// @dev Thrown when transfer to or from the zero address occurs. 8 | /// @param from Sending address. 9 | /// @param to Receiving address. 10 | error TransferError(address from, address to); 11 | 12 | /// @notice Transfer event. 13 | /// @dev Logged on successful transfer. 14 | /// @param from Sending address. 15 | /// @param to Receiving address. 16 | /// @param value Amount transferred. 17 | event Transfer(address indexed from, address indexed to, uint256 value); 18 | 19 | /// @notice Approval event. 20 | /// @dev Logged on approval. 21 | /// @param owner Owner address. 22 | /// @param spender Spender address allowed to transfer on behalf of `owner`. 23 | /// @param value Amount approved. 24 | event Approval(address indexed owner, address indexed spender, uint256 value); 25 | 26 | /// @notice Token name. 27 | string public name; 28 | 29 | /// @notice Ticker symbol. 30 | string public symbol; 31 | 32 | /// @notice Decimal places. 33 | uint8 public constant decimals = 18; 34 | 35 | /// @notice Total token supply. 36 | uint256 totalSupply; 37 | 38 | /// @notice HashMap maps accounts to their respective balances. 39 | mapping(address => uint256) balanceOf; 40 | 41 | /// @notice Nested HashMap maps owners to spenders to the spenders' respective allowances. 42 | mapping(address => mapping(address => uint256)) allowance; 43 | 44 | constructor(string memory _name, string memory _symbol) { 45 | name = _name; 46 | symbol = _symbol; 47 | } 48 | 49 | /// @notice Transfers from the caller to another address 50 | /// @dev Throws when receiver is zero address or when insufficient balance. 51 | /// @param to Receiver address. 52 | /// @param value Amount to transfer. 53 | function transfser(address to, uint256 value) external returns (bool) { 54 | if (to == address(0)) revert TransferError(msg.sender, to); 55 | 56 | balanceOf[msg.sender] -= value; 57 | balanceOf[to] += value; 58 | emit Transfer(msg.sender, to, value); 59 | return true; 60 | } 61 | 62 | /// @notice Transfers from one address to another 63 | /// @dev Throws when receiver is zero address, when insufficient balance, or when insufficient 64 | /// allowance. 65 | /// @param from Sender address. 66 | /// @param to Receiver address. 67 | /// @param value Amount to transfer. 68 | function transferFrom(address from, address to, uint256 value) external returns (bool) { 69 | if (from == address(0) || to == address(0)) revert TransferError(from, to); 70 | 71 | // only deduct from allowance IF the max is not approved AND the `from` address is not the 72 | // caller. 73 | if (msg.sender != from && allowance[from][msg.sender] < type(uint256).max) 74 | allowance[from][msg.sender] -= value; 75 | 76 | balanceOf[from] -= value; 77 | balanceOf[to] += value; 78 | emit Transfer(from, to, value); 79 | return true; 80 | } 81 | 82 | /// @notice Approves an amount for a `spender` to transfer on behalf of the caller. 83 | /// @dev Setting it to the `type(uint256).max` value will give infinite approval. 84 | /// @param spender Spender address. 85 | /// @param value Amount approved for `spender` to transfer on behalf of the caller. 86 | function approve(address spender, uint256 value) external returns (bool) { 87 | allowance[msg.sender][spender] = value; 88 | emit Approval(msg.sender, spender, value); 89 | return true; 90 | } 91 | 92 | /// @dev Internal mint function. Logs `Transfer` from zero address. 93 | function _mint(address to, uint256 value) internal { 94 | balanceOf[to] += value; 95 | totalSupply += value; 96 | emit Transfer(address(0), to, value); 97 | } 98 | } -------------------------------------------------------------------------------- /15-mint-tokens/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'mint-tokens' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /15-mint-tokens/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "mint-tokens" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /15-mint-tokens/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /15-mint-tokens/sway/out/debug/mint-tokens-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "b256", 12 | "components": null, 13 | "typeParameters": null 14 | }, 15 | { 16 | "typeId": 2, 17 | "type": "struct Address", 18 | "components": [ 19 | { 20 | "name": "value", 21 | "type": 1, 22 | "typeArguments": null 23 | } 24 | ], 25 | "typeParameters": null 26 | } 27 | ], 28 | "functions": [ 29 | { 30 | "inputs": [ 31 | { 32 | "name": "recipient", 33 | "type": 2, 34 | "typeArguments": null 35 | } 36 | ], 37 | "name": "mint_tokens", 38 | "output": { 39 | "name": "", 40 | "type": 0, 41 | "typeArguments": null 42 | }, 43 | "attributes": null 44 | } 45 | ], 46 | "loggedTypes": [], 47 | "messagesTypes": [], 48 | "configurables": [] 49 | } -------------------------------------------------------------------------------- /15-mint-tokens/sway/out/debug/mint-tokens-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /15-mint-tokens/sway/out/debug/mint-tokens.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/15-mint-tokens/sway/out/debug/mint-tokens.bin -------------------------------------------------------------------------------- /15-mint-tokens/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{ 4 | constants::ZERO_B256, 5 | asset::mint_to_address 6 | }; 7 | 8 | abi MintTokens { 9 | fn mint_tokens(recipient: Address); 10 | } 11 | 12 | impl MintTokens for Contract { 13 | fn mint_tokens(recipient: Address) { 14 | let amount_to_mint = 1_000_000; 15 | mint_to_address(recipient, ZERO_B256, amount_to_mint); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /16-hashing/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "hashing" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /16-hashing/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /16-hashing/solidity/Hashing.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Hasher 5 | contract Hashes { 6 | /// @notice Hashes via `keccak256` algorithm. 7 | function hashKeccak() public pure returns (bytes32) { 8 | return keccak256(abi.encode("Hello", "world!")); 9 | } 10 | 11 | /// @notice Hashes via `sha256` algorithm. 12 | function hashSha() public pure returns (bytes32) { 13 | return sha256(abi.encode("Hello", "world!")); 14 | } 15 | } -------------------------------------------------------------------------------- /16-hashing/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'hashing' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /16-hashing/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "hashing" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /16-hashing/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /16-hashing/sway/out/debug/hashing-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "b256", 6 | "components": null, 7 | "typeParameters": null 8 | } 9 | ], 10 | "functions": [ 11 | { 12 | "inputs": [], 13 | "name": "hash_keccack", 14 | "output": { 15 | "name": "", 16 | "type": 0, 17 | "typeArguments": null 18 | }, 19 | "attributes": null 20 | }, 21 | { 22 | "inputs": [], 23 | "name": "hash_sha", 24 | "output": { 25 | "name": "", 26 | "type": 0, 27 | "typeArguments": null 28 | }, 29 | "attributes": null 30 | } 31 | ], 32 | "loggedTypes": [], 33 | "messagesTypes": [], 34 | "configurables": [] 35 | } -------------------------------------------------------------------------------- /16-hashing/sway/out/debug/hashing-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /16-hashing/sway/out/debug/hashing.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/16-hashing/sway/out/debug/hashing.bin -------------------------------------------------------------------------------- /16-hashing/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::hash::{Hash, keccak256, sha256}; 4 | 5 | abi Hashes { 6 | fn hash_keccack() -> b256; 7 | fn hash_sha() -> b256; 8 | } 9 | 10 | impl Hashes for Contract { 11 | fn hash_keccack() -> b256 { 12 | keccak256(("Hello", "world!")) 13 | } 14 | 15 | fn hash_sha() -> b256 { 16 | sha256(("Hello", "world!")) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /17-ec-recover/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "ec-recover" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /17-ec-recover/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /17-ec-recover/solidity/ECRecover.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Elliptic Curve Ops 5 | contract ECRecover { 6 | /// @notice Recovers a public address, given a message hash and signature. 7 | /// @param ethSignedMessageHash Hash of message. 8 | /// @param signature EC signature. 9 | function recoverSigner( 10 | bytes32 ethSignedMessageHash, 11 | bytes memory signature 12 | ) public pure returns (address) { 13 | (bytes32 r, bytes32 s, uint8 v) = splitSignature(signature); 14 | 15 | // A recovered public key 16 | return ecrecover(ethSignedMessageHash, v, r, s); 17 | } 18 | 19 | /// @notice Splits an EC signature into its `r`, `s`, and `v` components. 20 | /// @param sig Signature to split. 21 | function splitSignature(bytes memory sig) 22 | public 23 | pure 24 | returns (bytes32 r, bytes32 s, uint8 v) 25 | { 26 | require(sig.length == 65, "invalid signature length"); 27 | assembly { 28 | r := mload(add(sig, 32)) 29 | s := mload(add(sig, 64)) 30 | v := byte(0, mload(add(sig, 96))) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /17-ec-recover/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'ec-recover' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /17-ec-recover/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "ec-recover" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /17-ec-recover/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /17-ec-recover/sway/out/debug/ec-recover-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "[_; 2]", 12 | "components": [ 13 | { 14 | "name": "__array_element", 15 | "type": 2, 16 | "typeArguments": null 17 | } 18 | ], 19 | "typeParameters": null 20 | }, 21 | { 22 | "typeId": 2, 23 | "type": "b256", 24 | "components": null, 25 | "typeParameters": null 26 | }, 27 | { 28 | "typeId": 3, 29 | "type": "struct B512", 30 | "components": [ 31 | { 32 | "name": "bytes", 33 | "type": 1, 34 | "typeArguments": null 35 | } 36 | ], 37 | "typeParameters": null 38 | } 39 | ], 40 | "functions": [ 41 | { 42 | "inputs": [ 43 | { 44 | "name": "signature", 45 | "type": 3, 46 | "typeArguments": null 47 | }, 48 | { 49 | "name": "msg_hash", 50 | "type": 2, 51 | "typeArguments": null 52 | } 53 | ], 54 | "name": "use_ec_recover", 55 | "output": { 56 | "name": "", 57 | "type": 0, 58 | "typeArguments": null 59 | }, 60 | "attributes": null 61 | } 62 | ], 63 | "loggedTypes": [], 64 | "messagesTypes": [], 65 | "configurables": [] 66 | } -------------------------------------------------------------------------------- /17-ec-recover/sway/out/debug/ec-recover-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /17-ec-recover/sway/out/debug/ec-recover.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/17-ec-recover/sway/out/debug/ec-recover.bin -------------------------------------------------------------------------------- /17-ec-recover/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{b512::B512, ecr::{ec_recover, ec_recover_address}}; 4 | 5 | abi ECRecover { 6 | fn use_ec_recover(signature: B512, msg_hash: b256); 7 | } 8 | 9 | impl ECRecover for Contract { 10 | fn use_ec_recover(signature: B512, msg_hash: b256) { 11 | // A recovered public key 12 | let public_key = ec_recover(signature, msg_hash).unwrap(); 13 | 14 | // A recovered Fuel address 15 | let result_address = ec_recover_address(signature, msg_hash).unwrap(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /18-reentrancy-guard/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "re-entrancy" 7 | source = "member" 8 | dependencies = ["std"] 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /18-reentrancy-guard/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /18-reentrancy-guard/solidity/Re-entrancy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | /// @title Reentrancy Guard 5 | contract ReEntrancyGuard { 6 | /// @dev Lock variable. 7 | bool internal locked; 8 | 9 | /// @dev NonReentrant error. Thrown when reentrancy is detected. 10 | error NonReentrant(); 11 | 12 | modifier noReentrant() { 13 | if (locked) revert NonReentrant(); 14 | locked = true; 15 | _; 16 | locked = false; 17 | } 18 | 19 | /// @notice Non reentrant function. 20 | /// @dev Throws when reentered. 21 | function safeFunction() public noReentrant { 22 | (bool success, ) = msg.sender.call(""); 23 | require(success, "call failed"); 24 | } 25 | } -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 're-entrancy' 7 | source = 'member' 8 | dependencies = ['std'] 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Sarah Schwartz"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "re-entrancy" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/out/debug/re-entrancy-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "()", 6 | "components": [], 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "enum ReentrancyError", 12 | "components": [ 13 | { 14 | "name": "NonReentrant", 15 | "type": 0, 16 | "typeArguments": null 17 | } 18 | ], 19 | "typeParameters": null 20 | } 21 | ], 22 | "functions": [ 23 | { 24 | "inputs": [], 25 | "name": "safe_function", 26 | "output": { 27 | "name": "", 28 | "type": 0, 29 | "typeArguments": null 30 | }, 31 | "attributes": null 32 | } 33 | ], 34 | "loggedTypes": [ 35 | { 36 | "logId": 0, 37 | "loggedType": { 38 | "name": "", 39 | "type": 1, 40 | "typeArguments": [] 41 | } 42 | } 43 | ], 44 | "messagesTypes": [], 45 | "configurables": [] 46 | } -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/out/debug/re-entrancy-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/out/debug/re-entrancy.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/18-reentrancy-guard/sway/out/debug/re-entrancy.bin -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | mod reentrancy; 4 | use reentrancy::reentrancy_guard; 5 | 6 | abi ReEntrancyGuard { 7 | fn safe_function(); 8 | } 9 | 10 | impl ReEntrancyGuard for Contract { 11 | fn safe_function() { 12 | reentrancy_guard(); 13 | // do something 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /18-reentrancy-guard/sway/src/reentrancy.sw: -------------------------------------------------------------------------------- 1 | library; 2 | // This has been moved due to https://github.com/FuelLabs/sway/issues/4160 3 | //! A reentrancy check for use in Sway contracts. 4 | //! Note that this only works in internal contexts. 5 | //! to prevent reentrancy: `assert(!is_reentrant());` 6 | use std::call_frames::*; 7 | use std::registers::frame_ptr; 8 | 9 | pub enum ReentrancyError { 10 | NonReentrant: (), 11 | } 12 | 13 | /// Reverts if the reentrancy pattern is detected in the contract in which this is called. 14 | /// Not needed if the Checks-Effects-Interactions (CEI) pattern is followed (as prompted by the 15 | /// compiler). 16 | /// > Caution: While this can protect against both single-function reentrancy and cross-function 17 | /// reentrancy attacks, it WILL NOT PREVENT a cross-contract reentrancy attack. 18 | pub fn reentrancy_guard() { 19 | require(!is_reentrant(), ReentrancyError::NonReentrant); 20 | } 21 | 22 | /// Returns `true` if the reentrancy pattern is detected, and `false` otherwise. 23 | /// 24 | /// Detects reentrancy by iteratively checking previous calls in the current call stack for a 25 | /// contract ID equal to the current contract ID. If a match is found, it returns true, else false. 26 | pub fn is_reentrant() -> bool { 27 | // Get our current contract ID 28 | let this_id = contract_id(); 29 | 30 | // Reentrancy cannot occur in an external context. If not detected by the time we get to the 31 | // bottom of the call_frame stack, then no reentrancy has occured. 32 | let mut call_frame_pointer = frame_ptr(); 33 | if !call_frame_pointer.is_null() { 34 | call_frame_pointer = get_previous_frame_pointer(call_frame_pointer); 35 | }; 36 | while !call_frame_pointer.is_null() { 37 | // get the ContractId value from the previous call frame 38 | let previous_contract_id = get_contract_id_from_call_frame(call_frame_pointer); 39 | if previous_contract_id == this_id { 40 | return true; 41 | }; 42 | call_frame_pointer = get_previous_frame_pointer(call_frame_pointer); 43 | } 44 | 45 | // The current contract ID wasn't found in any contract calls prior to here. 46 | false 47 | } -------------------------------------------------------------------------------- /19-unsigned-integers/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "core" 3 | source = "path+from-root-C3992B43B72ADB8C" 4 | 5 | [[package]] 6 | name = "std" 7 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 8 | dependencies = ["core"] 9 | 10 | [[package]] 11 | name = "unsigned-ints" 12 | source = "member" 13 | dependencies = ["std"] 14 | -------------------------------------------------------------------------------- /19-unsigned-integers/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /19-unsigned-integers/solidity/UnsignedInts.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract UintOperations { 5 | function u64Operation(uint64 x, uint64 y) public pure returns (uint64){ 6 | return x + y; 7 | } 8 | 9 | function u128Operation(uint128 x, uint128 y) public pure returns (uint128){ 10 | return x + y; 11 | } 12 | 13 | function u256Operation(uint256 x, uint256 y) public pure returns (uint256) { 14 | return x + y; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /19-unsigned-integers/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'core' 3 | source = 'path+from-root-1AA1C8235B783A81' 4 | 5 | [[package]] 6 | name = 'std' 7 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 8 | dependencies = ['core'] 9 | 10 | [[package]] 11 | name = 'unsigned-ints' 12 | source = 'member' 13 | dependencies = ['std'] 14 | -------------------------------------------------------------------------------- /19-unsigned-integers/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Kin Chan"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "unsigned-ints" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /19-unsigned-integers/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /19-unsigned-integers/sway/out/debug/unsigned-ints-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "struct U128", 6 | "components": [ 7 | { 8 | "name": "upper", 9 | "type": 2, 10 | "typeArguments": null 11 | }, 12 | { 13 | "name": "lower", 14 | "type": 2, 15 | "typeArguments": null 16 | } 17 | ], 18 | "typeParameters": null 19 | }, 20 | { 21 | "typeId": 1, 22 | "type": "struct U256", 23 | "components": [ 24 | { 25 | "name": "a", 26 | "type": 2, 27 | "typeArguments": null 28 | }, 29 | { 30 | "name": "b", 31 | "type": 2, 32 | "typeArguments": null 33 | }, 34 | { 35 | "name": "c", 36 | "type": 2, 37 | "typeArguments": null 38 | }, 39 | { 40 | "name": "d", 41 | "type": 2, 42 | "typeArguments": null 43 | } 44 | ], 45 | "typeParameters": null 46 | }, 47 | { 48 | "typeId": 2, 49 | "type": "u64", 50 | "components": null, 51 | "typeParameters": null 52 | } 53 | ], 54 | "functions": [ 55 | { 56 | "inputs": [ 57 | { 58 | "name": "x", 59 | "type": 2, 60 | "typeArguments": null 61 | }, 62 | { 63 | "name": "y", 64 | "type": 2, 65 | "typeArguments": null 66 | } 67 | ], 68 | "name": "u128_operation", 69 | "output": { 70 | "name": "", 71 | "type": 0, 72 | "typeArguments": null 73 | }, 74 | "attributes": null 75 | }, 76 | { 77 | "inputs": [ 78 | { 79 | "name": "x", 80 | "type": 2, 81 | "typeArguments": null 82 | }, 83 | { 84 | "name": "y", 85 | "type": 2, 86 | "typeArguments": null 87 | } 88 | ], 89 | "name": "u256_operation", 90 | "output": { 91 | "name": "", 92 | "type": 1, 93 | "typeArguments": null 94 | }, 95 | "attributes": null 96 | }, 97 | { 98 | "inputs": [ 99 | { 100 | "name": "x", 101 | "type": 2, 102 | "typeArguments": null 103 | }, 104 | { 105 | "name": "y", 106 | "type": 2, 107 | "typeArguments": null 108 | } 109 | ], 110 | "name": "u64_operation", 111 | "output": { 112 | "name": "", 113 | "type": 2, 114 | "typeArguments": null 115 | }, 116 | "attributes": null 117 | } 118 | ], 119 | "loggedTypes": [], 120 | "messagesTypes": [], 121 | "configurables": [] 122 | } -------------------------------------------------------------------------------- /19-unsigned-integers/sway/out/debug/unsigned-ints-storage_slots.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /19-unsigned-integers/sway/out/debug/unsigned-ints.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/19-unsigned-integers/sway/out/debug/unsigned-ints.bin -------------------------------------------------------------------------------- /19-unsigned-integers/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{u128::U128, u256::U256}; 4 | 5 | abi UintOperations { 6 | fn u64_operation(x: u64, y: u64) -> u64; 7 | fn u128_operation(x: u64, y: u64) -> U128; 8 | fn u256_operation(x: u64, y: u64) -> U256; 9 | } 10 | 11 | // All overflows and exceptions are handled natively by the VM 12 | impl UintOperations for Contract { 13 | // max of 64 bits natively 14 | fn u64_operation(x: u64, y: u64) -> u64 { 15 | return x + y 16 | } 17 | 18 | // u128 are split into two 64 bits 19 | // (upper << 64) + lower 20 | fn u128_operation(x: u64, y: u64) -> U128 { 21 | return U128 { 22 | upper: 0, 23 | lower: x, 24 | } + U128 { 25 | upper: 0, 26 | lower: y, 27 | }; 28 | } 29 | 30 | // u256 are split into four 64 bits 31 | // (a << 192) + (b << 128) + (c << 64) + d 32 | fn u256_operation(x: u64, y: u64) -> U256 { 33 | return U256 { 34 | a: 0, 35 | b: 0, 36 | c: 0, 37 | d: x, 38 | } + U256 { 39 | a: 0, 40 | b: 0, 41 | c: 0, 42 | d: y, 43 | }; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /20-contract-calls/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "contract-calls" 3 | source = "member" 4 | dependencies = ["std"] 5 | 6 | [[package]] 7 | name = "core" 8 | source = "path+from-root-C3992B43B72ADB8C" 9 | 10 | [[package]] 11 | name = "std" 12 | source = "git+https://github.com/fuellabs/sway?tag=v0.49.1#2ac7030570f22510b0ac2a7b5ddf7baa20bdc0e1" 13 | dependencies = ["core"] 14 | -------------------------------------------------------------------------------- /20-contract-calls/Forc.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["./sway"] -------------------------------------------------------------------------------- /20-contract-calls/solidity/ContractCalls.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.24; 3 | 4 | contract Bob { 5 | uint256 public favouriteNumber = 0; 6 | 7 | function copyAlicesNumber(address _alicesAddress) public returns(uint256) { 8 | IAlice alicesContract = IAlice(_alicesAddress); 9 | 10 | favouriteNumber = alicesContract.getFavouriteNumber(); 11 | 12 | return favouriteNumber; 13 | } 14 | } 15 | 16 | interface IAlice { 17 | function getFavouriteNumber() external view returns(uint256); 18 | } 19 | 20 | /* 21 | DEPLOYED CONTRACT 22 | 23 | contract Alice { 24 | uint256 public favouriteNumber = 42; 25 | 26 | function getFavouriteNumber() public view returns(uint256) { 27 | return favouriteNumber; 28 | } 29 | } 30 | */ 31 | -------------------------------------------------------------------------------- /20-contract-calls/sway/Forc.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = 'contract-calls' 3 | source = 'member' 4 | dependencies = ['std'] 5 | 6 | [[package]] 7 | name = 'core' 8 | source = 'path+from-root-1AA1C8235B783A81' 9 | 10 | [[package]] 11 | name = 'std' 12 | source = 'git+https://github.com/fuellabs/sway?tag=v0.38.0#2d16d70ab9d5ab0de0255941048f811b6d07c6b1' 13 | dependencies = ['core'] 14 | -------------------------------------------------------------------------------- /20-contract-calls/sway/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Kin Chan"] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract-calls" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /20-contract-calls/sway/fuel-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "beta-5" -------------------------------------------------------------------------------- /20-contract-calls/sway/out/debug/contract-calls-abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "types": [ 3 | { 4 | "typeId": 0, 5 | "type": "b256", 6 | "components": null, 7 | "typeParameters": null 8 | }, 9 | { 10 | "typeId": 1, 11 | "type": "u64", 12 | "components": null, 13 | "typeParameters": null 14 | } 15 | ], 16 | "functions": [ 17 | { 18 | "inputs": [ 19 | { 20 | "name": "alices_address", 21 | "type": 0, 22 | "typeArguments": null 23 | } 24 | ], 25 | "name": "copy_alices_number", 26 | "output": { 27 | "name": "", 28 | "type": 1, 29 | "typeArguments": null 30 | }, 31 | "attributes": [ 32 | { 33 | "name": "storage", 34 | "arguments": [ 35 | "write", 36 | "read" 37 | ] 38 | } 39 | ] 40 | } 41 | ], 42 | "loggedTypes": [], 43 | "messagesTypes": [], 44 | "configurables": [] 45 | } -------------------------------------------------------------------------------- /20-contract-calls/sway/out/debug/contract-calls-storage_slots.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed", 4 | "value": "0000000000000000000000000000000000000000000000000000000000000000" 5 | } 6 | ] -------------------------------------------------------------------------------- /20-contract-calls/sway/out/debug/contract-calls.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/sway-vs-solidity/466dde7ea32c69537f63a2d649c0ca819364bad9/20-contract-calls/sway/out/debug/contract-calls.bin -------------------------------------------------------------------------------- /20-contract-calls/sway/src/interface.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | abi Alice { 4 | #[storage(read)] 5 | fn get_favourite_number() -> u64; 6 | } 7 | 8 | /* 9 | DEPLOYED CONTRACT 10 | 11 | storage { 12 | favourite_number: u64 = 42, 13 | } 14 | 15 | impl Alice for Contract { 16 | #[storage(read)] 17 | fn get_favourite_number() -> u64 { 18 | return storage.favourite_number; 19 | } 20 | } 21 | */ 22 | -------------------------------------------------------------------------------- /20-contract-calls/sway/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | mod interface; 4 | use interface::Alice; 5 | 6 | abi Bob { 7 | #[storage(write, read)] 8 | fn copy_alices_number(contract_id: b256) -> u64; 9 | } 10 | 11 | storage { 12 | favourite_number: u64 = 0, 13 | } 14 | 15 | impl Bob for Contract { 16 | #[storage(write, read)] 17 | fn copy_alices_number(alices_address: b256) -> u64 { 18 | let alice_contract = abi(Alice, alices_address); 19 | 20 | storage.favourite_number.write(alice_contract.get_favourite_number()); 21 | 22 | return storage.favourite_number.read(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2023 Scott Chacon and others 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sway vs Solidity Examples 2 | 3 | ### This repo contains 1:1 examples showing how to implement example Solidity code in Sway. 4 | 5 | > **Note** 6 | > [Sway](https://github.com/FuelLabs/sway) is a language under heavy development therefore the applications may not be the most ergonomic. Over time they should receive updates / improvements in order to demonstrate how Sway can be used in real use cases. 7 | 8 |

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |

19 | 20 | ## Repository Structure 21 | 22 | Each project in this repository is self-contained and operates independently of the others. This means that means for every `Sway` project example there is a subsequent `Solidity` example. 23 | 24 | However, it's important to keep in mind that all the projects are integrated within the same CI system. Therefore, any updates or modifications to one project must guarantee that the other projects still function correctly. 25 | 26 | To illustrate the structure of the repository, below is a visual representation. 27 | 28 | ``` 29 | ├── sway-vs-solidity 30 | │ └── 01-hello-world 31 | │ ├── solidity 32 | │ └── sway 33 | │ ... 34 | │ 35 | ├── LICENSE 36 | └── README.md 37 | ``` 38 | 39 | ## Examples 40 | 1. [Hello World](./01-hello-world/): A basic contract that stores a variable `greeting`, and has a function to return the value of that variable. 41 | 42 | [Hello World Twitter Thread](https://twitter.com/schwartzswartz/status/1617902570630156294) 43 | 44 | 2. [Counter](./02-counter/): This contract stores a variable called `counter` in persistent storage, and has two functions: `count` which reads the value of `counter`, and `increment` which adds 1 to the current value of `counter`. 45 | 46 | 3. [Logging](./03-logging/): This contract logs the number `42` and the string `Hello World!` whenever someone calls the `logger` function. 47 | 48 | [Logging Twitter Thread](https://twitter.com/SwayLang/status/1620077543322947584) 49 | 50 | 4. [Storage](./04-storage/): This contract stores five types of state variables: a number, a string, a boolean, a map, and an array. It has functions to read and update their values. 51 | 52 | [Storage Twitter Thread](https://twitter.com/schwartzswartz/status/1621166627093094400) 53 | 54 | 5. [Conditional](./05-conditional/): This contract just includes some simple conditional logic to demonstrate the syntax. 55 | 56 | 6. [Structs](./08-functions/): A `Todo` contract that stores a persistent array of `Todo` structs, and has functions to create a new `Todo`, get the value of one, and update an existing one. 57 | 58 | 7. [Errors](./07-errors/): This contract demonstrates a few ways to throw errors. 59 | 60 | 8. [Functions](./08-functions/): A contract with internal and external functions. 61 | 62 | 9. [Amounts](./09-amounts/): This contract shows the units used for amounts of ether. 63 | 64 | 10. [Message Info](./10-message-info/): This contract shows how to access the message sender and message amount sent in a transaction. 65 | 66 | [Message Info Twitter Thread](https://twitter.com/SwayLang/status/1622991008488206337) 67 | 68 | 11. [Gas Info](./11-gas-info/): This contract shows how to access information about the gas used in a transaction. 69 | 70 | 12. [Contract Info](./12-contract-info/): This contract shows how to access the contract's balance and id. 71 | 72 | 13. [Block Info](./13-block-info/): This contract shows how to access information about the current block. 73 | 74 | 14. [Transfer](./14-transfer/): This contract shows the methods available to transfer assets. 75 | 76 | 15. [Mint Tokens](./15-mint-tokens/): A contract that mint tokens. 77 | 78 | 16. [Hashing](./16-hashing/): A contract that uses sha256 and keccack256 hashing. 79 | 80 | 17. [EC Recover](./17-ec-recover/): This contract shows how to recover a public key from a signed message. 81 | 82 | 18. [Re-entrancy Guard](./18-reentrancy-guard/): A contract that includes a guard against a re-entrancy attack. 83 | 84 | [Re-entrancy Guard Twitter Thread](https://twitter.com/SwayLang/status/1621210727275970560) 85 | 86 | 19. [Unsigned Integers](./19-unsigned-integers/): This contract shows how unsigned integers are handled beyond the native max of u64 87 | 88 | 20. [Contract Calls](./20-contract-calls/): This contract shows how a contract can call other contracts through interfaces 89 | 90 | ## Running a project 91 | In order to utilize our tools and run any of the projects, it is necessary for you to clone this repository and follow the [installation steps](https://fuellabs.github.io/sway/v0.38.0/book/introduction/installation.html) for the Fuel tool suite. 92 | 93 | ## Contributing 94 | Feel free to open up an issue or create a PR ❤️ --------------------------------------------------------------------------------