The purpose of this repository is to contain libraries which users can import and use that are not part of the standard library.
These libraries contain helper functions and other tools valuable to blockchain development.
NOTE: Sway is a language under heavy development therefore the libraries 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.
- Ownership is used to apply restrictions on functions such that only a single user may call them.
- Admin is used to apply restrictions on functions such that only a select few users may call them like a whitelist.
- Pausable allows contracts to implement an emergency stop mechanism.
- Reentrancy is used to detect and prevent reentrancy attacks.
- Merkle Proof is used to verify Binary Merkle Trees computed off-chain.
- Fixed Point Number is an interface to implement fixed-point numbers.
- Signed Integers is an interface to implement signed integers.
- Queue is a linear data structure that provides First-In-First-Out (FIFO) operations.
To import a library, a dependency should be added to the project's Forc.toml
file under [dependencies]
. The following shows adding the Merkle Proof Library.
merkle_proof = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.1.0" }
NOTE: Be sure to set the tag to the latest release.
You may then import your desired library in your Sway Smart Contract as so:
use merkle_proof::<library_function>;
For example, to import the verify_proof()
function use the following statement:
use merkle_proof::binary_merkle_proof::verify_proof;
There are two sets of tests that should be run: inline tests and sdk-harness tests.
In order to run the inline tests, make sure you are in the libs/
folder of this repository sway-libs/libs/<you are here>
.
Run the tests:
forc test
Once these tests have passed, make sure you are in the tests/
folder of this repository sway-libs/tests/<you are here>
.
Run the tests:
forc test && cargo test
NOTE: This may take a while depending on your hardware, future improvements to Sway will decrease build times. After this has been run once, indiviual test projects may be built on their own to save time.
Any instructions related to using a specific library should be found within the README.md of that library.
NOTE: All projects currently use
forc v0.47.0
,fuels-rs v0.46.0
andfuel-core 0.20.8
.
Check out the book for more info!