Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions .github/workflows/checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache cargo registry
uses: actions/cache@v3
- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
Expand All @@ -44,7 +45,7 @@ jobs:

- name: Install Rust toolchain and wasm32 target per directory
run: |
for dir in example_code/applications/* example_code/basic_examples/*; do
for dir in example_code/internal/* example_code/external/*; do
if [[ -d "$dir" && -f "$dir/rust-toolchain.toml" ]]; then
toolchain_version=$(grep '^channel' "$dir/rust-toolchain.toml" | cut -d '"' -f 2)
rustup toolchain install "$toolchain_version"
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/update-external-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Update External Examples from SDK

on:
schedule:
- cron: '0 0 * * 0' # Every Sunday at 00:00 UTC
workflow_dispatch: # Allows manual trigger

jobs:
update-examples:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/
~/.cargo/git/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Install jq & curl
run: sudo apt-get update && sudo apt-get install -y jq curl

- name: Make update script executable
run: chmod +x ./update-external-examples.sh

- name: Run update script
run: ./update-external-examples.sh

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: auto-update external examples from stylus-sdk-rs"
branch: "chore/update-external-examples"
title: "chore: Auto-update external examples from stylus-sdk-rs"
body: |
This PR automatically updates the `example_code/external` directory with the latest examples
from the `stylus-sdk-rs` repository and bumps `stylus-sdk` and `stylus-tools` dependencies to their latest versions.
labels: |
chore
dependencies
assignees: ""
reviewers: ""
# Allows the workflow to run even if no changes are detected
# but for this specific workflow, we only want a PR if changes occur
# so we remove the comment-if-no-changes option.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ next-env.d.ts
/example_code/**/target/**

# report
check_results.log
check_results.log
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".submodules/stylus-sdk-rs"]
path = .submodules/stylus-sdk-rs
url = https://github.com/OffchainLabs/stylus-sdk-rs.git
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# stylus-by-example

Welcome to Stylus by Example! This repository contains a collection of concise, runnable examples that demonstrate core concepts and common patterns for writing smart contracts with [Arbitrum Stylus](https://docs.arbitrum.io/stylus/introduction). Whether you're new to Stylus or looking to deepen your understanding, these examples are designed to be a quick and accessible resource.

## Structure

The repository is organized into two main categories of examples:

- **`example_code/external/`**: These are direct copies of examples from the [stylus-sdk-rs](https://github.com/OffchainLabs/stylus-sdk-rs) repository. They are kept up-to-date automatically by a GitHub Actions workflow that copies the latest versions and updates their `Cargo.toml` dependencies to use the latest `stylus-sdk` and `stylus-tools` from [crates.io](https://crates.io).

- **`example_code/internal/`**: These are custom examples developed specifically for this repository, often showcasing more complex applications or unique patterns not covered by the external examples.

## Getting Started

First, run the development server:
**1. Clone the repository:**

```bash
pnpm dev
git clone https://github.com/OffchainLabs/stylus-by-example
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
**2. Explore the examples:**

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
Navigate to `example_code/external/` or `example_code/internal/` to browse the available examples. Each example is a self-contained Rust project with its own `Cargo.toml`.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
**3. Build and test:**

## Learn More
To build and test an example, navigate into its directory and run `cargo build` and `cargo test`:

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
```bash
cd example_code/external/hello_world
cargo build
cargo test
```

## Deploy on Vercel
## Contributions

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
We welcome contributions to Stylus by Example! If you have a new example idea, an improvement to an existing one, or a bug fix, please feel free to open a pull request.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
## License

## Learn more
If you'd like to know more about Stylus, feel free to take a look at [Arbitrum's Stylus technical pages](https://docs.arbitrum.io/stylus/stylus-gentle-introduction).
This project is licensed under the MIT License.
28 changes: 24 additions & 4 deletions checker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,22 @@ process_directory() {
echo -e "Processing Directory: $dir_name"
echo -e "============================================"

df -h # Check disk space at the start of directory processing

for dir in "$base_dir"/*/; do
if [ -d "$dir" ]; then
folder_name=$(basename "$dir")
echo -e "\nEntering directory: $folder_name"
cd "$dir" || continue

# Clean the project before running checks to free up disk space
echo "Disk space before clean:"
df -h .
rm -rf target # More aggressive cleaning
cargo clean
echo "Disk space after clean:"
df -h .

if grep -q 'stylus-sdk' Cargo.toml; then
if [ "$NO_UPDATE" = false ]; then
update_cargo_toml "Cargo.toml"
Expand All @@ -118,6 +128,9 @@ process_directory() {

# Run checks
check_output=$(cargo stylus check -e $rpc_url 2>&1)
echo "Disk space after check:"
df -h .

if [ $? -eq 0 ]; then
echo -e "Check passed in $folder_name"
check_status="PASSED"
Expand All @@ -132,6 +145,8 @@ process_directory() {

if [ "$check_status" == "PASSED" ]; then
export_output=$(cargo stylus export-abi 2>&1)
echo "Disk space after export-abi:"
df -h .
if [ $? -eq 0 ]; then
echo -e "Export ABI successful in $folder_name"
else
Expand All @@ -143,6 +158,11 @@ process_directory() {
fi
fi

# Clean up ABI, binary files, and target directory after each example
rm -f "*.abi" "*.bin"
rm -rf target
cargo clean

cd - > /dev/null || exit
echo -e "---------------------------------"
fi
Expand All @@ -153,10 +173,10 @@ process_directory() {
}

# Directories to process
APPLICATIONS_DIR="example_code/applications"
BASIC_EXAMPLES_DIR="example_code/basic_examples"
INTERNAL_DIR="example_code/internal"
EXTERNAL_DIR="example_code/external"

process_directory "$APPLICATIONS_DIR"
process_directory "$BASIC_EXAMPLES_DIR"
process_directory "$INTERNAL_DIR"
process_directory "$EXTERNAL_DIR"

echo -e "\nAll checks and exports completed! Logs are available in '/tmp/check_results.log'."
31 changes: 0 additions & 31 deletions example_code/applications/english_auction/Cargo.toml.bak

This file was deleted.

Loading