diff --git a/.github/workflows/actions.yaml b/.github/workflows/actions.yaml index b3b7776..16e880d 100644 --- a/.github/workflows/actions.yaml +++ b/.github/workflows/actions.yaml @@ -74,6 +74,7 @@ jobs: 'math_lib', 'imports', 'predicate', + 'script', 'big_number', ] diff --git a/README.md b/README.md index db12362..6b35e31 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # sway-by-example-lib -Library for compiled sway programs + +Library of compiled Sway programs to showcase accessible code for the Sway language. + diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 5cf73cc..5494252 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -25,5 +25,6 @@ - [Vector](./vector.md) - [Base Asset](./base-asset.md) - [Predicate](./predicate.md) +- [Script](./script.md) - [Big Numbers](./big-numbers.md) - [SRC20](./src20.md) diff --git a/docs/src/index.md b/docs/src/index.md index bf68c74..58dceff 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,3 +1,3 @@ # Sway By Example -An introduction to Sway with simple examples +Library of compiled Sway programs to showcase accessible code for the Sway language. diff --git a/docs/src/script.md b/docs/src/script.md new file mode 100644 index 0000000..f56bf2f --- /dev/null +++ b/docs/src/script.md @@ -0,0 +1,18 @@ +# Script + +Examples of a script program type in Sway + +| | Predicates | Scripts | +|--------------------------------|------------|-----------| +| Access data on chain | ❌ | ✅ | +| Read data from smart contracts | ❌ | ✅ | +| Check date or time | ❌ | ✅ | +| Read block hash or number | ❌ | ✅ | +| Read input coins | ✅ | ✅ | +| Read output coins | ✅ | ✅ | +| Read transaction scripts | ✅ | ✅ | +| Read transaction bytecode | ✅ | ✅ | + +```sway +{{#include ../examples/script/src/main.sw}} +``` diff --git a/examples/script/.gitignore b/examples/script/.gitignore new file mode 100644 index 0000000..77d3844 --- /dev/null +++ b/examples/script/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/examples/script/Forc.lock b/examples/script/Forc.lock new file mode 100644 index 0000000..26cb8e5 --- /dev/null +++ b/examples/script/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-566CA1D5F8BEAFBF" + +[[package]] +name = "script" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "git+https://github.com/fuellabs/sway?tag=v0.49.3#0dc6570377ee9c4a6359ade597fa27351e02a728" +dependencies = ["core"] diff --git a/examples/script/Forc.toml b/examples/script/Forc.toml new file mode 100644 index 0000000..3274a6d --- /dev/null +++ b/examples/script/Forc.toml @@ -0,0 +1,7 @@ +[project] +authors = ["Fuel DevRel"] +entry = "main.sw" +license = "Apache-2.0" +name = "script" + +[dependencies] diff --git a/examples/script/src/main.sw b/examples/script/src/main.sw new file mode 100644 index 0000000..46f4769 --- /dev/null +++ b/examples/script/src/main.sw @@ -0,0 +1,15 @@ +script; + +abi ContractA { + fn test_func(x: u64) -> Identity; +} + +const CONTRACTA_ID = 0x79fa8779bed2f36c3581d01c79df8da45eee09fac1fd76a5a656e16326317ef0; + +fn main(a: u64) { + let c = abi(ContractA, CONTRACTA_ID); + + // Call a contract multiple times + log(c.test_func(a)); + log(c.test_func(a + 32)); +}