Note 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.
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.
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.
To illustrate the structure of the repository, below is a visual representation.
├── sway-vs-solidity
│ └── 01-hello-world
│ ├── solidity
│ └── sway
│ ...
│
├── LICENSE
└── README.md
-
Hello World: A basic contract that stores a variable
greeting
, and has a function to return the value of that variable. -
Counter: This contract stores a variable called
counter
in persistent storage, and has two functions:count
which reads the value ofcounter
, andincrement
which adds 1 to the current value ofcounter
. -
Logging: This contract logs the number
42
and the stringHello World!
whenever someone calls thelogger
function. -
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.
-
Conditional: This contract just includes some simple conditional logic to demonstrate the syntax.
-
Structs: A
Todo
contract that stores a persistent array ofTodo
structs, and has functions to create a newTodo
, get the value of one, and update an existing one. -
Errors: This contract demonstrates a few ways to throw errors.
-
Functions: A contract with internal and external functions.
-
Amounts: This contract shows the units used for amounts of ether.
-
Message Info: This contract shows how to access the message sender and message amount sent in a transaction.
-
Gas Info: This contract shows how to access information about the gas used in a transaction.
-
Contract Info: This contract shows how to access the contract's balance and id.
-
Block Info: This contract shows how to access information about the current block.
-
Transfer: This contract shows the methods available to transfer assets.
-
Mint Tokens: A contract that mint tokens.
-
Hashing: A contract that uses sha256 and keccack256 hashing.
-
EC Recover: This contract shows how to recover a public key from a signed message.
-
Re-entrancy Guard: A contract that includes a guard against a re-entrancy attack.
-
Unsigned Integers: This contract shows how unsigned integers are handled beyond the native max of u64
-
Contract Calls: This contract shows how a contract can call other contracts through interfaces
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 for the Fuel tool suite.
Feel free to open up an issue or create a PR ❤️