> ## Documentation Index
> Fetch the complete documentation index at: https://developers.stellar.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Contract Lifecycle

> Manage the lifecycle of a Stellar smart contract using the CLI

To manage the lifecycle of a Stellar smart contract using the CLI, follow these steps:

1. Set your preferred network. For this guide, we will use `testnet`. A list of available networks can be found [here](/docs/networks.md)

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar network use testnet
```

2. Create an identity for Alice:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar keys generate alice -q
```

3. Fund the identity:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar keys fund alice
```

4. Deploy a contract:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar keys use alice
```

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar contract deploy --wasm /path/to/contract.wasm --alias mycontract
```

This will display the resulting contract ID, e.g.:

```
CBB65ZLBQBZL5IYHDHEEPCVUUMFOQUZSQKAJFV36R7TZETCLWGFTRLOQ
```

To learn more about how to build contract `.wasm` files, take a look at our [getting started tutorial](/docs/build/smart-contracts/getting-started/setup.md).

5. Invoke a contract function:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar contract invoke --id mycontract -- <FUNCTION>
```

6. View the contract's state:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar contract read --id mycontract --durability <DURABILITY> --key <KEY>
```

Note: `<DURABILITY>` is either `persistent` or `temporary`. `KEY` provides the key of the storage entry being read.

7. Manage expired states:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
stellar contract extend --id mycontract --ledgers-to-extend 1000 --durability <DURABILITY> --key <KEY>
```

This extends the state of the instance provided by the given key to at least 1000 ledgers from the current ledger.
