Simple Counter contract written in Rust.
Follow the instructions in the Stylus quickstart to configure your development environment.
You'll also need Foundry to interact with the contract.
You can use cargo stylus to check that your contract is compatible with Stylus by running
cargo stylus check
With the following command you can deploy it to an Arbitrum chain
cargo stylus deploy --endpoint $RPC_URL --private-key $PRIVATE_KEY
Alternatively, you can use the bash scripts available to build and deploy the contract:
For unit testing, this example integrates the motsu library from OpenZeppelin. To run unit tests, you can simply use
cargo test --locked --lib
Alternatively, you can use the bash script available test-unit.sh.
For integration tests, this example integrates a fork of the e2e library from OpenZeppelin available here. To run the tests you need to run a nitro-testnode. A script is available to clone and run the nitro-testnode, nitro-testnode.sh. Once the nitro-testnode is running, you can run the e2e tests using the script available test-e2e.sh.
The scripts
folder contains several other scripts that make individual calls to perform the most important actions:
- ./scripts/getCount.sh to get the current counter
- ./scripts/increment.sh to increment the current counter
- ./scripts/setCount.sh to set the current counter
Remember to set the environment variables in an .env
file.
Instructions to setup a local dev node can be found here.