Back to Sway

Counter

docs/book/src/examples/counter.md

0.71.0643 B
Original Source

Counter

The following is a simple example of a contract which implements a counter. Both the initialize_counter() and increment_counter() ABI methods return the currently set value.

bash
forc template --template-name counter my_counter_project
sway
{{#include ../../../../examples/counter/src/main.sw}}

Build and deploy

The following commands can be used to build and deploy the contract. For a detailed tutorial, refer to Building and Deploying.

bash
# Build the contract
forc build

# Deploy the contract
forc deploy --testnet