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

chore: bump intro-to-sway guide #282

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/builds/sway
Submodule sway updated 930 files
2 changes: 1 addition & 1 deletion docs/fuels-ts
Submodule fuels-ts updated 107 files
10 changes: 0 additions & 10 deletions docs/guides/docs/contract-quickstart/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ Getting started with Fuel as a smart contract developer is as simple as:
commentType="{/*"
/>

### Testnet toolchain

To use the `testnet` toolchain, run the commands below:

```sh
fuelup self update
fuelup toolchain install testnet
fuelup default testnet
```

## Generating a counter contract

Run the command below to generate a counter contract in Sway:
Expand Down
6 changes: 4 additions & 2 deletions docs/guides/docs/counter-dapp/building-a-frontend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ To build a frontend application for the counter contract, we'll do the following

## Install the Fuel Browser Wallet

{/*install_wallet:example:start*/}
Our frontend application will allow users to connect with a wallet, so you'll need to have a browser wallet installed.

The current Fuel Wallet release can only be used with the `beta-5` network. To use the new testnet, you must use the [Fuel Development Wallet](https://chromewebstore.google.com/detail/fuel-wallet-development/hcgmehahnlbhpilepakbdinkhhaackmc).
Before going to the next steps, install the [Fuel Wallet](https://chromewebstore.google.com/detail/fuel-wallet/dldjpboieedgcmpkchcjcbijingjcgok) extension.

You can get test funds for the testnet by visiting the [Testnet Faucet](https://faucet-testnet.fuel.network/).
Once you've setup your wallet, click the "Faucet" button in the wallet to get some testnet tokens.
{/*install_wallet:example:end*/}

## Initialize a React project

Expand Down
20 changes: 8 additions & 12 deletions docs/guides/docs/counter-dapp/building-a-smart-contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,18 @@ parent:
commentType="{/*"
/>

### Testnet toolchain

To use the `testnet` toolchain, run the commands below:

```sh
fuelup self update
fuelup toolchain install testnet
fuelup default testnet
```

{/* ### Already have `fuelup` installed?
### Already have `fuelup` installed?

{/*already_installed:example:start*/}
If you already have `fuelup` installed, run the commands below to make sure you are on the most up-to-date toolchain.

```sh
fuelup self update
fuelup update
fuelup default latest
``` */}
```

{/*already_installed:example:end*/}

## Your First Sway Project

Expand Down Expand Up @@ -381,6 +374,7 @@ tree .
4 directories, 8 files
```

{/*rust_harness:example:start*/}
We have two new files!

- The `Cargo.toml` is the manifest for our new test harness and specifies the required dependencies including `fuels` (the Fuel Rust SDK).
Expand All @@ -394,6 +388,8 @@ fuels = { version = "0.62.0", features = ["fuel-core-lib"] }
tokio = { version = "1.12", features = ["rt", "macros"] }
```

{/*rust_harness:example:end*/}

Now that we have our default test harness, let's add a useful test to it.

At the bottom of `test/harness.rs` below the `can_get_contract_id()` test, add the `test_increment` test function below to verify that the value of the counter gets incremented:
Expand Down
14 changes: 6 additions & 8 deletions docs/guides/docs/frontend-quickstart/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ Getting started with Fuel as a frontend or fullstack developer is as simple as:
commentType="{/*"
/>

### Testnet toolchain
### Already have `fuelup` installed?

To use the `testnet` toolchain, run the commands below:

```sh
fuelup self update
fuelup toolchain install testnet
fuelup default testnet
```
<TextImport
file="../counter-dapp/building-a-smart-contract.mdx"
comment="already_installed"
commentType="{/*"
/>

## Generating a counter dapp

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/docs/intro-to-sway/checkpoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ To deploy, use the following command if you've already set up the forc-wallet an
forc deploy --testnet
```

After deploying, remember to save your contract ID. You'll need it for frontend integration.
After deploying, you'll be able to find your contract ID in the `contract/out/deployments` folder. You'll need this for frontend integration.
14 changes: 8 additions & 6 deletions docs/guides/docs/intro-to-sway/contract-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Next, we'll utilize the `require` statement to ensure the sent asset is the corr

The `require` statement accepts two arguments: a condition, and a value that's logged when the condition is false. Should the condition evaluate as false, the entire transaction is rolled back, leaving no changes.

In this case, the condition checks if the `asset_id` matches the `BASE_ASSET_ID`—the default asset associated with the base blockchain, imported from the standard library. For example, if the base blockchain is Ethereum, the base asset would be ETH.
In this case, the condition checks if the `asset_id` matches the base asset ID — the default asset associated with the base blockchain - using `AssetId::base()`. For example, if the base blockchain is Ethereum, the base asset would be ETH.

If there's a mismatch in the asset, for instance, if someone attempts to purchase an item using a different coin, we'll trigger the custom error previously defined, passing along the `asset_id`.

Expand Down Expand Up @@ -207,14 +207,16 @@ To get the details for an item, we can create a read-only function that returns
lang="sway"
/>

To return a value in a function, you can use the `return` keyword, similar to JavaScript. Alternatively, you can omit the semicolon in the last line to return that value like in Rust. Although both methods are effective.
To return a value in a function, you can use the `return` keyword, similar to JavaScript. Alternatively, you can omit the semicolon in the last line to return that value like in Rust.

```sway
fn my_function(num: u64) -> u64{
// returning the num variable
fn my_function_1(num: u64) -> u64{
// returns the num variable
return num;

// this would also work:
}

fn my_function_2(num: u64) -> u64{
// returns the num variable
num
}
```
Expand Down
2 changes: 0 additions & 2 deletions docs/guides/docs/intro-to-sway/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ parent:

# Introduction to Sway Language for JavaScript Developers

> **Note:** This guide has not yet been updated for the new `testnet` network.

If you're familiar with JavaScript and have a basic understanding of blockchain fundamentals, you can swiftly grasp how to build full-stack decentralized applications on Fuel using Sway. Once you get a handle on Sway's essentials, you'll be able to begin building your own dapp.

Within this tutorial, we will be crafting a Sway contract for an online marketplace similar to Amazon, where:
Expand Down
16 changes: 15 additions & 1 deletion docs/guides/docs/intro-to-sway/prerequisites.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ parent:
commentType="{/*"
/>

Make sure you have the latest version of the [Fuel Wallet](https://chrome.google.com/webstore/detail/fuel-wallet/dldjpboieedgcmpkchcjcbijingjcgok) installed.
### Already have `fuelup` installed?

<TextImport
file="../counter-dapp/building-a-smart-contract.mdx"
comment="already_installed"
commentType="{/*"
/>

### Fuel Wallet

<TextImport
file="../counter-dapp/building-a-frontend.mdx"
comment="install_wallet"
commentType="{/*"
/>

Additionally for this guide, ensure you're using Node.js/npm version {props.nodeVersion}.
You can check your Node.js version with:
Expand Down
12 changes: 9 additions & 3 deletions docs/guides/docs/intro-to-sway/rust-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ action={{
/>

```bash
cargo generate --init fuellabs/sway templates/sway-test-rs --name sway-store --tag v0.49.3
cargo generate --init fuellabs/sway templates/sway-test-rs --name sway-store
```

<TextImport
file="../counter-dapp/building-a-smart-contract.mdx"
comment="rust_harness"
commentType="{/*"
/>

## Imports

We will be changing the existing `harness.rs` test file that has been generated. Firstly we need to change the imports. By importing the Fuel Rust SDK you will get majority of the functionalities housed within the prelude.
Expand Down Expand Up @@ -96,7 +102,7 @@ action={{
## Test Cases

Given the immutable nature of smart contracts, it's important to cover all potential edge cases in your tests.
Let's write the test cases at the bottom of our `harness.rs` file.
Let's delete the example `can_get_contract_id` test case and start writing some test cases at the bottom of our `harness.rs` file.

### Setting Owner

Expand Down Expand Up @@ -194,7 +200,7 @@ If you have followed the previous steps correctly your `harness.rs` test file sh

## Running the Tests

To run the test located in `tests/harness.rs`, use:
To run the test located in `tests/harness.rs`, run the command below inside your `contract` folder:

<TestAction
id="cargo-test"
Expand Down
Loading
Loading