{"id":19460103,"url":"https://github.com/offchainlabs/stylus-hello-world","last_synced_at":"2025-04-04T15:06:03.405Z","repository":{"id":191744477,"uuid":"683140760","full_name":"OffchainLabs/stylus-hello-world","owner":"OffchainLabs","description":"Project starter template for writing Arbitrum Stylus programs in Rust","archived":false,"fork":false,"pushed_at":"2025-03-20T14:45:19.000Z","size":754,"stargazers_count":46,"open_issues_count":3,"forks_count":31,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-03-28T14:04:46.256Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OffchainLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"licenses/Apache-2.0","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-25T17:41:36.000Z","updated_at":"2025-03-20T14:39:52.000Z","dependencies_parsed_at":"2023-08-31T12:57:31.108Z","dependency_job_id":"3aec95ab-3c81-48bd-8a83-0d454e1766b1","html_url":"https://github.com/OffchainLabs/stylus-hello-world","commit_stats":null,"previous_names":["offchainlabs/stylus-hello-world"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-hello-world","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-hello-world/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-hello-world/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fstylus-hello-world/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OffchainLabs","download_url":"https://codeload.github.com/OffchainLabs/stylus-hello-world/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198440,"owners_count":20900079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T17:35:37.519Z","updated_at":"2025-04-04T15:06:03.374Z","avatar_url":"https://github.com/OffchainLabs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Image](./header.png)\n\n# Stylus Hello World\n\nProject starter template for writing Arbitrum Stylus programs in Rust using the [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs). It includes a Rust implementation of a basic counter Ethereum smart contract:\n\n```js\n// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\n\ncontract Counter {\n    uint256 public number;\n\n    function setNumber(uint256 newNumber) public {\n        number = newNumber;\n    }\n\n    function increment() public {\n        number++;\n    }\n}\n```\n\nTo set up more minimal example that still uses the Stylus SDK, use `cargo stylus new --minimal \u003cYOUR_PROJECT_NAME\u003e` under [OffchainLabs/cargo-stylus](https://github.com/OffchainLabs/cargo-stylus).\n\n## Quick Start \n\nInstall [Rust](https://www.rust-lang.org/tools/install), and then install the Stylus CLI tool with Cargo\n\n```bash\ncargo install --force cargo-stylus cargo-stylus-check\n```\n\nAdd the `wasm32-unknown-unknown` build target to your Rust compiler:\n\n```\nrustup target add wasm32-unknown-unknown\n```\n\nYou should now have it available as a Cargo subcommand:\n\n```bash\ncargo stylus --help\n```\n\nThen, clone the template:\n\n```\ngit clone https://github.com/OffchainLabs/stylus-hello-world \u0026\u0026 cd stylus-hello-world\n```\n\n### Testnet Information\n\nAll testnet information, including faucets and RPC endpoints can be found [here](https://docs.arbitrum.io/stylus/reference/testnet-information).\n\n### ABI Export\n\nYou can export the Solidity ABI for your program by using the `cargo stylus` tool as follows:\n\n```bash\ncargo stylus export-abi\n```\n\nwhich outputs:\n\n```js\n/**\n * This file was automatically generated by Stylus and represents a Rust program.\n * For more information, please see [The Stylus SDK](https://github.com/OffchainLabs/stylus-sdk-rs).\n */\n\ninterface Counter {\n    function setNumber(uint256 new_number) external;\n\n    function increment() external;\n}\n```\n\nExporting ABIs uses a feature that is enabled by default in your Cargo.toml:\n\n```toml\n[features]\nexport-abi = [\"stylus-sdk/export-abi\"]\n```\n\n## Deploying\n\nYou can use the `cargo stylus` command to also deploy your program to the Stylus testnet. We can use the tool to first check\nour program compiles to valid WASM for Stylus and will succeed a deployment onchain without transacting. By default, this will use the Stylus testnet public RPC endpoint. See here for [Stylus testnet information](https://docs.arbitrum.io/stylus/reference/testnet-information)\n\n```bash\ncargo stylus check\n```\n\nIf successful, you should see:\n\n```bash\nFinished release [optimized] target(s) in 1.88s\nReading WASM file at stylus-hello-world/target/wasm32-unknown-unknown/release/stylus-hello-world.wasm\nCompressed WASM size: 8.9 KB\nProgram succeeded Stylus onchain activation checks with Stylus version: 1\n```\n\nNext, we can estimate the gas costs to deploy and activate our program before we send our transaction. Check out the [cargo-stylus](https://github.com/OffchainLabs/cargo-stylus) README to see the different wallet options for this step:\n\n```bash\ncargo stylus deploy \\\n  --private-key-path=\u003cPRIVKEY_FILE_PATH\u003e \\\n  --estimate-gas\n```\n\nYou will then see the estimated gas cost for deploying before transacting:\n\n```bash\nDeploying program to address e43a32b54e48c7ec0d3d9ed2d628783c23d65020\nEstimated gas for deployment: 1874876\n```\n\nThe above only estimates gas for the deployment tx by default. To estimate gas for activation, first deploy your program using `--mode=deploy-only`, and then run `cargo stylus deploy` with the `--estimate-gas` flag, `--mode=activate-only`, and specify `--activate-program-address`.\n\n\nHere's how to deploy:\n\n```bash\ncargo stylus deploy \\\n  --private-key-path=\u003cPRIVKEY_FILE_PATH\u003e\n```\n\nThe CLI will send 2 transactions to deploy and activate your program onchain.\n\n```bash\nCompressed WASM size: 8.9 KB\nDeploying program to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09\nEstimated gas: 1973450\nSubmitting tx...\nConfirmed tx 0x42db…7311, gas used 1973450\nActivating program at address 0x457b1ba688e9854bdbed2f473f7510c476a3da09\nEstimated gas: 14044638\nSubmitting tx...\nConfirmed tx 0x0bdb…3307, gas used 14044638\n```\n\nOnce both steps are successful, you can interact with your program as you would with any Ethereum smart contract.\n\n## Calling Your Program\n\nThis template includes an example of how to call and transact with your program in Rust using [ethers-rs](https://github.com/gakonst/ethers-rs) under the `examples/counter.rs`. However, your programs are also Ethereum ABI equivalent if using the Stylus SDK. **They can be called and transacted with using any other Ethereum tooling.**\n\nBy using the program address from your deployment step above, and your wallet, you can attempt to call the counter program and increase its value in storage:\n\n```rs\nabigen!(\n    Counter,\n    r#\"[\n        function number() external view returns (uint256)\n        function setNumber(uint256 number) external\n        function increment() external\n    ]\"#\n);\nlet counter = Counter::new(address, client);\nlet num = counter.number().call().await;\nprintln!(\"Counter number value = {:?}\", num);\n\nlet _ = counter.increment().send().await?.await?;\nprintln!(\"Successfully incremented counter via a tx\");\n\nlet num = counter.number().call().await;\nprintln!(\"New counter number value = {:?}\", num);\n```\n\nBefore running, set the following env vars or place them in a `.env` file (see: [.env.example](./.env.example)) in this project:\n\n```\nRPC_URL=https://sepolia-rollup.arbitrum.io/rpc\nSTYLUS_CONTRACT_ADDRESS=\u003cthe onchain address of your deployed program\u003e\nPRIV_KEY_PATH=\u003cthe file path for your priv key to transact with\u003e\n```\n\nNext, run:\n\n```\ncargo run --example counter --target=\u003cYOUR_ARCHITECTURE\u003e\n```\n\nWhere you can find `YOUR_ARCHITECTURE` by running `rustc -vV | grep host`. For M1 Apple computers, for example, this is `aarch64-apple-darwin` and for most Linux x86 it is `x86_64-unknown-linux-gnu`\n\n## Build Options\n\nBy default, the cargo stylus tool will build your project for WASM using sensible optimizations, but you can control how this gets compiled by seeing the full README for [cargo stylus](https://github.com/OffchainLabs/cargo-stylus). If you wish to optimize the size of your compiled WASM, see the different options available [here](https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md).\n\n## Peeking Under the Hood\n\nThe [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs) contains many features for writing Stylus programs in Rust. It also provides helpful macros to make the experience for Solidity developers easier. These macros expand your code into pure Rust code that can then be compiled to WASM. If you want to see what the `stylus-hello-world` boilerplate expands into, you can use `cargo expand` to see the pure Rust code that will be deployed onchain.\n\nFirst, run `cargo install cargo-expand` if you don't have the subcommand already, then:\n\n```\ncargo expand --all-features --release --target=\u003cYOUR_ARCHITECTURE\u003e\n```\n\nWhere you can find `YOUR_ARCHITECTURE` by running `rustc -vV | grep host`. For M1 Apple computers, for example, this is `aarch64-apple-darwin`.\n\n## License\n\nThis project is fully open source, including an Apache-2.0 or MIT license at your choosing under your own copyright.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchainlabs%2Fstylus-hello-world","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffchainlabs%2Fstylus-hello-world","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchainlabs%2Fstylus-hello-world/lists"}