-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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: rewrite introduction #5956
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
049dc07
draft intro rewrite
sarahschwartz 1a43c9e
cleanup
sarahschwartz b05de0e
Merge branch 'master' into sarah/introduction
sarahschwartz 501a50e
spelling
sarahschwartz a9755cd
Merge branch 'sarah/introduction' of https://github.com/FuelLabs/sway…
sarahschwartz File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,4 +188,9 @@ tuple's | |
unary | ||
SRC | ||
DEX | ||
SubId | ||
SubId | ||
transpiler | ||
NFT | ||
namespacing | ||
unsafety | ||
prioritizations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,87 @@ | ||
# The Sway Programming Language | ||
|
||
Sway is a domain-specific language (DSL) for the [Fuel Virtual Machine (FuelVM)](https://fuellabs.github.io/fuel-specs/master/vm/index.html), a blockchain-optimized VM designed for the Fuel blockchain. Sway is based on [Rust](https://doc.rust-lang.org/book/), and includes syntax to leverage a blockchain VM without needlessly verbose boilerplate. | ||
Welcome to the Sway programming language book 🌴. | ||
|
||
This book documents how to write smart contracts in Sway, along with how to install and use the Sway toolchain. | ||
**Q: Hi! What is Sway?** | ||
|
||
Before starting developing smart contracts in Sway, please keep in mind the [known issues and workarounds](./reference/known_issues_and_workarounds.md) of the language and toolchain. | ||
Sway is a domain-specific language (DSL) for the [Fuel Virtual Machine (Fuel VM)](https://docs.fuel.network/docs/specs/fuel-vm/), a blockchain-optimized VM designed for the Fuel blockchain. Sway is based on [Rust](https://doc.rust-lang.org/book/), and includes syntax to leverage a blockchain VM without needlessly verbose boilerplate. | ||
|
||
**Q: What does "domain-specific" mean?** | ||
|
||
A domain-specific language is a language that is made and used in a specific environment for a specific purpose, in this case execution in the Fuel VM. This differs from a general-purpose language that can be used for several environments and purposes, like Rust. | ||
|
||
**Q: Why doesn't Fuel use Solidity?** | ||
|
||
Sway aims to take the best of Solidity, and leave the worst. From Solidity, we took the notion of smart contract programming as a paradigm. This led to storage blocks, contract ABIs as entry points, and more. | ||
|
||
While Solidity has been used to make a lot of amazing contracts, as a developer it can also feel like a minefield for vulnerabilities. Instead of having to be a 10x developer to feel confident deploying a contract, Sway takes a lot of the the stress out of developing smart contracts. | ||
|
||
Sway provides multiple layers of safety. For one, we provide canonical tooling and "one right way" to do things. This results in less ambiguity and more correct and helpful tools. These tools ensure the programmer has nothing between them and the algorithm they are trying to implement. | ||
|
||
In addition, Sway has implemented static analysis checks like a [Checks, Effects, Interactions](./blockchain-development/calling_contracts.md#cei-pattern-violation-static-analysis) checker, state and storage purity checking, immutable-by-default semantics, and other static compile-time audits to promote safety. | ||
|
||
**Q: Why doesn't Fuel use Rust?** | ||
|
||
Sway aims to take the best of Rust, and leave out everything that doesn't make sense in blockchain. | ||
|
||
From Rust, we took the prioritizations of performance, control, and safety. In Rust, this means the borrow checker, safe parallelism (send and sync), annotated unsafety, etc., mainly to save the programmer from referencing freed memory, shared mutable state, and undesirable memory management. | ||
|
||
This is great for a general-purpose language model. Sway, however, is not general purpose. Sway targets a blockchain VM environment, where execution is not indefinite, and memory allocation and management are less concerned. Instead, we need to optimize for gas costs and contract-level safety. | ||
|
||
We applied the philosophy of performance, control, and safety and interpreted it in this new context. This is where Sway gets compile time checks of state mutability, namespacing of state variables, static analysis passes, and gas optimization. | ||
|
||
**Q: I don't know Rust or Solidity. Can I still learn Sway?** | ||
|
||
Yes! If you are familiar the basics of programming, blockchain, and using a terminal you can build with Sway. | ||
|
||
**Q: What can I build with Sway?** | ||
|
||
There are four types of programs you can build with Sway: contracts, scripts, predicates, and libraries. You can learn more about each of these in the [Program Types](./sway-program-types/index.md) section. | ||
|
||
**Q: Do I need to install anything?** | ||
|
||
If you want to develop with Sway in your local environment, you need to install [`fuelup`](https://docs.fuel.network/guides/installation/) and have an IDE such as [VSCode](https://code.visualstudio.com/). | ||
|
||
If you don't want to install anything just yet, you can use the [Sway Playground](https://www.sway-playground.org/) to edit, compile, and deploy Sway code. | ||
|
||
**Q: Where can I find example Sway code?** | ||
|
||
You can find example applications built with Sway in the [Sway Applications repository](https://github.com/FuelLabs/sway-applications) on GitHub. You can also find projects building on Fuel in the [Fuel ecosystem home](https://app.fuel.network/ecosystem). | ||
|
||
**Q: What is the standard library?** | ||
|
||
The [standard library](./introduction/standard_library.md), also referred to as the `std-lib`, is a library that offers core functions and helpers for developing in Sway. The standard library has it's own [reference documentation](https://fuellabs.github.io/sway/master/std/) that has detailed information about each module in the `std-lib`. | ||
|
||
**Q: What are Sway standards?** | ||
|
||
Similar to ERC standards for Ethereum and Solidity, Sway has it's own SRC standards that help enable cross compatibility across different smart contracts. For more information on using a Sway Standard, you can check out the [Sway-Standards Repository](https://github.com/FuelLabs/sway-standards). | ||
|
||
**Q: How can I make a token?** | ||
|
||
Sway has multiple native assets. To mint a new native asset, check out the [native assets](./blockchain-development/native_assets.md) page. | ||
|
||
**Q: How can I make an NFT?** | ||
|
||
You can find an example of an NFT contract in Sway in the [Sway Applications repo](https://github.com/FuelLabs/sway-applications/tree/master/NFT). | ||
|
||
**Q: How can I test Sway code?** | ||
|
||
Sway provides [unit testing](./testing/unit-testing.md), so you can test your Sway code with Sway. You can also use the Fuel [Rust SDK](https://docs.fuel.network/docs/fuels-rs/testing/) or [TypeScript SDK](https://docs.fuel.network/docs/fuels-ts/testing/) to test your Sway programs. | ||
|
||
**Q: How can I deploy a contract?** | ||
|
||
You can use the `forc deploy` command to deploy a contract. For a detailed guide on how to deploy a contract, refer to the the [quickstart guide](https://docs.fuel.network/docs/intro/quickstart-contract/). | ||
|
||
**Q: Is there a way to convert Solidity code to Sway?** | ||
|
||
Yes! You can use the Solidity to Sway transpiler built in to the [Sway Playground](https://www.sway-playground.org/) to convert Solidity code into Sway code. Note that the transpiler is still experimental, and may not work in every case. | ||
|
||
**Q: How can I get help with Sway?** | ||
|
||
If you run into an issue or have a question, post it on the [Fuel forum](https://forum.fuel.network/) so someone in the Fuel community can help. | ||
|
||
**Q: Where should I get started?** | ||
|
||
*Ready to build?* You can find step-by-step guides for how to build an application with Sway in the [Fuel Developer Guides](https://docs.fuel.network/guides/). | ||
|
||
*Want to read?* Get started by reading the [Introduction](./introduction/index.md) and [Basics](./basics/index.md) sections of this book. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.