# React E2E Counter (Sui)
This project is based on the Sui **Distributed Counter** example and the `react-e2e-counter` template from `@mysten/create-dapp`.[[Distributed Counter](https://docs.sui.io/guides/developer/app-examples/e2e-counter); [create-dapp e2e-counter](https://sdk.mystenlabs.com/dapp-kit/getting-started/create-dapp)]
It demonstrates an end-to-end Sui dApp:
- `move/counter/`: Move smart contract that defines the `Counter` object and its logic.[[Distributed Counter smart contracts](https://docs.sui.io/guides/developer/app-examples/e2e-counter#smart-contracts)]
- `src/`: React frontend that lets users create, increment, and reset counters.[[Distributed Counter frontend](https://docs.sui.io/guides/developer/app-examples/e2e-counter#frontend)]
## Prerequisites
- Sui CLI installed and configured (Testnet recommended).[[Distributed Counter](https://docs.sui.io/guides/developer/app-examples/e2e-counter)]
- Testnet SUI from the faucet: <https://faucet.sui.io>.[[Distributed Counter](https://docs.sui.io/guides/developer/app-examples/e2e-counter)]
- `pnpm` or `yarn` installed.[[Distributed Counter frontend](https://docs.sui.io/guides/developer/app-examples/e2e-counter#frontend)]
## Install dependencies
From the project root:
```bash
pnpm install
# or
yarn install- Configure Sui Testnet:
sui client new-env --alias testnet --rpc https://fullnode.testnet.sui.io:443
sui client switch --env testnet-
Make sure your Testnet address has SUI (via the faucet).[Distributed Counter]
-
Publish the
counterpackage:
cd move
sui client publish --gas-budget 100000000 counterCopy the packageId from the publish output; you will use it in the frontend configuration.[e2e-counter deployment]
Create or edit src/constants.ts and set the package IDs as follows:[Connecting your package]
export const DEVNET_COUNTER_PACKAGE_ID = "0xTODO";
export const TESTNET_COUNTER_PACKAGE_ID = "<YOUR_TESTNET_PACKAGE_ID>";
export const MAINNET_COUNTER_PACKAGE_ID = "0xTODO";If your project includes src/networkConfig.ts, update it to use these constants as shown in the e2e-counter example.[Connecting your package]
From the project root:
pnpm dev
# or
yarn devOpen the URL printed in the terminal (typically http://localhost:5173 or similar) in your browser.
This app follows the Sui Distributed Counter guide:[Distributed Counter]
- Creates shared
Counterobjects on-chain. - Lets any user increment a counter.
- Restricts resetting/setting the counter value to the
owneraddress. - Uses Programmable Transaction Blocks (PTBs) from the React frontend to call the Move functions.