Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: adding intro to sway #55

Merged
merged 98 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
0a0d471
Content is complete just need to revise grammar and formatting
calldelegation Sep 14, 2023
28abf3e
Majority of the information is here now time to make grammar edits
calldelegation Sep 15, 2023
f9d55a1
Fix UI
calldelegation Sep 15, 2023
0ae27af
Finished revisions
calldelegation Sep 18, 2023
d4104e3
Merge branch 'master' into add/intro-to-sway
calldelegation Sep 28, 2023
f3d4517
Adding intro to sway as submodule
calldelegation Sep 28, 2023
9925007
adding code imports and better code detection
calldelegation Oct 3, 2023
e47e170
fixing github audit
calldelegation Oct 3, 2023
82be9e4
Removing submodule and fixing audit
calldelegation Oct 3, 2023
04e73fa
Ready for review
calldelegation Oct 3, 2023
439e392
Ready for review
calldelegation Oct 3, 2023
e3e10c4
Revert "Ready for review"
calldelegation Oct 5, 2023
1341757
Revert "Ready for review"
calldelegation Oct 5, 2023
8e318ee
Revert "Removing submodule and fixing audit"
calldelegation Oct 5, 2023
9cd6f94
Audit fix
calldelegation Oct 5, 2023
882072b
Updated intro-to-sway submodule to latest commit
calldelegation Oct 5, 2023
c164b5c
Ready for review
calldelegation Oct 5, 2023
368ede7
Moving intro to sway example
calldelegation Oct 5, 2023
a5dbba6
Revert "Moving intro to sway example"
calldelegation Oct 5, 2023
9f2a15a
Update docs/guides/docs/intro-to-sway/contract-functions.mdx
calldelegation Oct 6, 2023
29fff8e
Update docs/guides/docs/intro-to-sway/contract-structs.mdx
calldelegation Oct 6, 2023
1596e5c
Update docs/guides/docs/intro-to-sway/contract-structs.mdx
calldelegation Oct 6, 2023
27fcf0b
Update docs/guides/docs/intro-to-sway/contract-abi.mdx
calldelegation Oct 6, 2023
8d3ca64
Update docs/guides/docs/intro-to-sway/contract-errors.mdx
calldelegation Oct 6, 2023
3db4642
small fixes
calldelegation Oct 6, 2023
c555b26
Merge branch 'master' into add/intro-to-sway
calldelegation Oct 6, 2023
445f7d2
Update docs/guides/docs/intro-to-sway/rust-sdk.mdx
calldelegation Oct 6, 2023
8771ba8
More changes
calldelegation Oct 6, 2023
765b331
Checkpoint before continuing to resolve more comments
calldelegation Oct 6, 2023
b3b7105
Going to continue on the weekend
calldelegation Oct 6, 2023
44b7f0d
Merge branch 'master' into add/intro-to-sway
calldelegation Oct 6, 2023
98990cf
Testing code import changeback
calldelegation Oct 7, 2023
1afa595
testing quickstart
calldelegation Oct 8, 2023
53dfc6d
Merge branch 'master' into add/intro-to-sway
calldelegation Oct 9, 2023
bc19df0
Finished
calldelegation Oct 9, 2023
f0fe288
Small change
calldelegation Oct 9, 2023
e302cf0
New code changes
calldelegation Oct 9, 2023
4388328
Andres comments
calldelegation Oct 10, 2023
1c6ac15
Merge branch 'master' into add/intro-to-sway
calldelegation Oct 10, 2023
357d725
Pausing for now
calldelegation Oct 11, 2023
2d42fba
Merge branch 'master' into add/intro-to-sway
calldelegation Oct 12, 2023
9be2a98
Merge branch 'master' into add/intro-to-sway
calldelegation Oct 12, 2023
306077c
Almost ready for review
calldelegation Nov 7, 2023
7b4e7c1
Fix linter
calldelegation Nov 7, 2023
4f8a265
Fix linter
calldelegation Nov 7, 2023
e1b1408
Fix
calldelegation Nov 7, 2023
d904f36
Lint
calldelegation Nov 7, 2023
67667c7
lint
calldelegation Nov 7, 2023
2465cd5
spell
calldelegation Nov 7, 2023
06bcbb6
Fixing indentation
calldelegation Nov 7, 2023
b10968e
Fix
calldelegation Nov 7, 2023
ce7c378
Imports are looking good now
calldelegation Nov 7, 2023
20dc554
Removing intro to sway git module
calldelegation Nov 8, 2023
2776aa9
Removing intro to sway git module
calldelegation Nov 8, 2023
f710fd9
Remove existing 'docs/guides/examples' from the index
calldelegation Nov 8, 2023
be78237
Submodule added
calldelegation Nov 8, 2023
28892e4
Merge branch 'master' into add/intro-to-sway
calldelegation Nov 12, 2023
57ebdd1
Fixing frontend tests
calldelegation Nov 13, 2023
61b5ab0
Merge branch 'add/intro-to-sway' of https://github.com/FuelLabs/docs-…
calldelegation Nov 13, 2023
3ad4063
Almost ready for review
calldelegation Nov 14, 2023
66170e6
fix lint
calldelegation Nov 14, 2023
64866af
Brining back in tests
calldelegation Nov 14, 2023
f0cc913
fix
calldelegation Nov 14, 2023
91a25b8
fix
calldelegation Nov 14, 2023
2b302c0
stupid
calldelegation Nov 14, 2023
f53cbc9
fix
calldelegation Nov 14, 2023
85b0f64
fix
calldelegation Nov 14, 2023
1b3128a
updating
calldelegation Nov 14, 2023
82d2804
Resetting checks
calldelegation Nov 14, 2023
22c7d8f
adding to it
calldelegation Nov 14, 2023
bb1b7e1
fix
calldelegation Nov 14, 2023
92b4865
Merge branch 'master' into add/intro-to-sway
calldelegation Nov 14, 2023
c17c8f0
Adding this for later
calldelegation Nov 15, 2023
c1e1c00
Merge branch 'add/intro-to-sway' of https://github.com/FuelLabs/docs-…
calldelegation Nov 15, 2023
d2a0378
Updating intro to sway side
calldelegation Nov 15, 2023
7e44dba
Update docs/guides/docs/intro-to-sway/typescript-sdk.mdx
calldelegation Nov 17, 2023
9c3c407
Update docs/guides/docs/intro-to-sway/typescript-sdk.mdx
calldelegation Nov 17, 2023
80b298e
Update docs/guides/docs/intro-to-sway/contract-abi.mdx
calldelegation Nov 17, 2023
07c337a
fix
calldelegation Nov 20, 2023
38c0475
conflicts
calldelegation Nov 20, 2023
18b94cd
testing singular
calldelegation Nov 20, 2023
f0e1f30
test only playwrite
calldelegation Nov 20, 2023
61e8f37
Playwrite tests seperate
calldelegation Nov 20, 2023
5a5cffe
parallelization
calldelegation Nov 20, 2023
70536df
more extraction fixes
calldelegation Nov 20, 2023
f4248a9
Ready for review
calldelegation Nov 20, 2023
79ea623
Merge branch 'master' into add/intro-to-sway
calldelegation Nov 20, 2023
3f9c689
small fixes
calldelegation Nov 20, 2023
75d6d0e
Merge branch 'add/intro-to-sway' of https://github.com/FuelLabs/docs-…
calldelegation Nov 20, 2023
c3fc3db
fix
calldelegation Nov 20, 2023
4065d98
Sarah changes
calldelegation Nov 20, 2023
257d4ce
Reaedy
calldelegation Nov 21, 2023
f1ac82c
Ready
calldelegation Nov 21, 2023
f01bcbd
Fixing test
calldelegation Nov 21, 2023
48bf9fc
Missing label
calldelegation Nov 21, 2023
068d84b
Merge branch 'master' into add/intro-to-sway
calldelegation Nov 23, 2023
002a881
Merge branch 'master' into add/intro-to-sway
calldelegation Nov 28, 2023
1c85b26
Merge branch 'master' into add/intro-to-sway
calldelegation Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions .github/workflows/guides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ jobs:
- name: Lint Check
run: markdownlint --config .markdownlint.yaml --ignore-path .markdownlintignore '**/*.mdx'

## QUICKSTART TEST
quickstart-test:
## QUICKSTART E2E TESTS
quickstart-e2e-tests:
timeout-minutes: 30
name: build-quickstart-contract
name: Quickstart E2E Tests
runs-on: ubuntu-latest
steps:
strategy:
matrix:
# note: must match the names in test.spec.ts
guide:
- "dev quickstart"
- "intro to sway"

steps:
# SETUP
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -74,26 +80,13 @@ jobs:
- name: Set Default Beta-4 Toolchain
run: fuelup toolchain install beta-4 && fuelup default beta-4

# BUILD & RUN QUICKSTART CONTRACT TEST
- name: Build Contract
run: forc build --path ./docs/guides/examples/quickstart/counter-contract
- name: Run contract tests
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path ./docs/guides/examples/quickstart/counter-contract/Cargo.toml
- name: Check Cargo fmt & clippy
run: |
cd docs/guides/examples/quickstart/counter-contract
cargo fmt --all --check
cargo clippy --all-targets --all-features
# RUN E2E TESTS
- name: Run Playwright tests for ${{ matrix.guide }}
run: xvfb-run --auto-servernum pnpm test:guides --grep "${{ matrix.guide }}"

# RUN QUICKSTART E2E TEST
- name: Run Playwright tests
run: xvfb-run --auto-servernum pnpm test:guides
- uses: actions/upload-artifact@v2
if: always()
with:
name: playwright-report
name: playwright-report-${{ matrix.guide }}
path: playwright-report/
retention-days: 30
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
[submodule "docs/fuel-specs"]
path = docs/fuel-specs
url = https://github.com/FuelLabs/fuel-specs.git
[submodule "docs/guides/examples/intro-to-sway"]
path = docs/guides/examples/intro-to-sway
url = https://github.com/FuelLabs/intro-to-sway.git
[submodule "docs/latest/sway"]
path = docs/latest/sway
url = https://github.com/FuelLabs/sway.git
Expand Down
2 changes: 1 addition & 1 deletion docs/about-fuel/networks/beta-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ This installs the following components and versions:
To set the `beta-3` toolchain as your default, run

```console
$ fuelup default beta-3
fuelup default beta-3
default toolchain set to 'beta-3-aarch64-apple-darwin'
```

Expand Down
6 changes: 6 additions & 0 deletions docs/guides/docs/guides.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"featured": true,
"tags": ["Getting Started", "Full Stack"]
},
"intro_to_sway": {
"title": "Introduction to Sway for Javascript developers",
"description": "Learn Sway fundamentals by building a marketplace dApp.",
"featured": false,
"tags": ["Full Stack"]
},
"running_a_node": {
"title": "Running a Node",
"description": "Run a local Fuel node.",
Expand Down
16 changes: 8 additions & 8 deletions docs/guides/docs/installation/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ The Fuel toolchain is built on top of the Rust programming language. To install

Run the following command in your shell; this downloads and runs `rustup-init.sh`, which in turn downloads and runs the correct version of the `rustup-init` executable for your platform.

{/*install_rust_command:example:start*/}
{/*ANCHOR: install_rust_command*/}

```console
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

{/*install_rust_command:example:end*/}
{/*ANCHOR: install_rust_command*/}

Check the official Rust documentation to get more information on [installing the Rust toolchain](https://www.rust-lang.org/tools/install).

Expand All @@ -51,13 +51,13 @@ This will install `forc`, `forc-client`, `forc-fmt`, `forc-lsp`, `forc-wallet` a

👉 Just paste the following line in your terminal and press *Enter*.

{/*install_fuelup_command:example:start*/}
{/*ANCHOR: install_fuelup_command*/}

```sh
curl --proto '=https' --tlsv1.2 -sSf https://install.fuel.network/fuelup-init.sh | sh
calldelegation marked this conversation as resolved.
Show resolved Hide resolved
```

{/*install_fuelup_command:example:end*/}
{/*ANCHOR_END: install_fuelup_command*/}

> 🚧 Be aware that currently we do not natively support Windows. If you wish to use `fuelup` on Windows, please use Windows Subsystem for Linux.

Expand Down Expand Up @@ -142,13 +142,13 @@ To properly interact with the {props.fuelTestnetInlineCode} network it is necess
👉 Run the following command to install the {props.fuelTestnetInlineCode} toolchain:
{/*install_testnet:example:end*/}

{/*install_testnet_command:example:start*/}
{/*ANCHOR: install_testnet_command*/}

```console
fuelup toolchain install beta-4
```

{/*install_testnet_command:example:end*/}
{/*ANCHOR_END: install_testnet_command*/}

If the toolchain was successfully installed, you will see this output:

Expand All @@ -162,13 +162,13 @@ The toolchain was installed correctly, however is not in use yet. Next, you need
👉 Set {props.fuelTestnetInlineCode} as your default toolchain with the following command:
{/*set_default_testnet:example:end*/}

{/*set_default_testnet_command:example:start*/}
{/*ANCHOR: set_default_testnet_command*/}

```console
fuelup default beta-4
```

{/*set_default_testnet_command:example:end*/}
{/*ANCHOR_END: set_default_testnet_command*/}

You will get the following output indicating that you have successfully set {props.fuelTestnetInlineCode} as your default toolchain.

Expand Down
73 changes: 73 additions & 0 deletions docs/guides/docs/intro-to-sway/checkpoint.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
title: Checkpoint
category: Intro to Sway
parent:
label: All Guides
link: /guides
---

# Checkpoint

## Sway Contract Checkpoint

If you have followed the previous steps correctly your `main.sw` marketplace contract should look like this:

<CodeImport
file="../../examples/intro-to-sway/contract/src/main.sw"
comment="all"
commentType="//"
lang="sway"
/>

## Building the contract

Here's a polished version of your instructions:

To format your contract, execute the command:

<TestAction
id="format-contract"
action={{
name: 'runCommand',
commandFolder: 'guides-testing/fuel-project/contract'
}}
/>

```sh
calldelegation marked this conversation as resolved.
Show resolved Hide resolved
forc fmt
```

To compile your contract, navigate to the contract folder and run:

<TestAction
id="build-contract"
action={{
name: 'runCommand',
commandFolder: 'guides-testing/fuel-project/contract'
}}
/>

```sh
forc build
```

Congratulations! You've successfully written a full contract in Sway!

Post-compilation, the system will automatically generate `abi.json`, `storage_slots.json`, and `contract.bin`. You can locate these files in the following directory:

```sh
contract/out/debug/*
```

## Deploying the contract

For detailed steps on deploying this contract, refer to the official Fuel developer quickstart guide:
[Deploy the Contract](/guides/quickstart/building-a-smart-contract/#deploy-the-contract)

To deploy, use the following command if you've already set up the forc-wallet and have testnet funds in your account. If not, follow the instructions above.

```sh
forc deploy --testnet
```

After deploying, remember to save your contract ID. You'll need it for frontend integration.
40 changes: 40 additions & 0 deletions docs/guides/docs/intro-to-sway/contract-abi.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: ABI
category: Intro to Sway
parent:
label: All Guides
link: /guides
---

# Defining the ABI

Next, we will define our ABI. ABI stands for Application Binary Interface. In a Sway contract, it serves as an outline of all the functions within the contract. For each function, you need to specify its name, input types, return types, level of storage access, and if it's payable.

The ABI for our contract is structured as follows. Write the ABI provided below into your `main.sw` file:

<TestAction
id="sway-abi"
action={{
name: 'modifyFile',
filepath: 'guides-testing/fuel-project/contract/src/main.sw'
}}
/>

<CodeImport
file="../../examples/intro-to-sway/contract/src/main.sw"
comment="abi"
commentType="//"
lang="sway"
/>

Don't be worried about understanding the specifics of each function at this moment. We will dive into detailed explanations in the "Functions" section.

## Functions Structure

A function is defined using the `fn` keyword. In Sway, snake case is the convention, so instead of naming a function `myFunction`, you would name it `my_function`.
calldelegation marked this conversation as resolved.
Show resolved Hide resolved

If the function returns a value, its return type must be defined using a skinny arrow. Additionally, if the function has parameters, their types must also be specified. Semicolons are *required* at the end of each statement.

If a function either reads from or writes to storage, you need to specify the access level above the function using annotations like `#[storage(read)]` or `#[storage(read, write)]`.

For functions that are expected to receive funds when called, such as the `buy_item` function, the `#[payable]` annotation is required.
40 changes: 40 additions & 0 deletions docs/guides/docs/intro-to-sway/contract-errors.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Errors
category: Intro to Sway
parent:
label: All Guides
link: /guides
---

# Defining Error Handling

Enumerations, commonly referred to as enums, are a type that can represent one of several possible variants. Within our contract, we can employ enums to craft custom error messages, facilitating more precise error handling within functions.

Copy the custom error block into your `main.sw` file:

<TestAction
id="sway-errors"
action={{
name: 'modifyFile',
filepath: 'guides-testing/fuel-project/contract/src/main.sw'
}}
/>

<CodeImport
file="../../examples/intro-to-sway/contract/src/main.sw"
comment="error_handling"
commentType="//"
lang="sway"
/>

Within our contract, we can anticipate various scenarios where we'd want to throw an error and halt the transaction:

1. Someone might attempt to pay for an item using an incorrect currency.
2. An individual could try to purchase an item without possessing sufficient coins.
3. Someone other than the owner might attempt to withdraw funds from the contract.

For each situation, we can define specific return types for the errors:

- For the `IncorrectAssetId` error, we can return the submitted asset id, which is of type `AssetId`.
- In the case of the `NotEnoughTokens` error, we can define the return type as `u64` to indicate the number of coins involved.
- For the `OnlyOwner` error, we can utilize the `Identity` of the message sender as the return value.
Loading
Loading