Skip to main content

Contract Lifecycle

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

  1. Create an identity for Alice:
stellar keys generate alice -q
  1. Fund the identity:
stellar keys fund alice
  1. Deploy a contract:
stellar contract deploy --wasm /path/to/contract.wasm --source alice --network testnet

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.

  1. Initialize the contract:
stellar contract invoke --id <CONTRACT_ID> --source alice --network testnet -- initialize --param1 value1 --param2 value2
  1. Invoke a contract function:
stellar contract invoke --id <CONTRACT_ID> --source alice --network testnet -- function_name --arg1 value1 --arg2 value2
  1. View the contract's state:
stellar contract read --id <CONTRACT_ID> --network testnet --durability <DURABILITY> --key <KEY>

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

  1. Manage expired states:
stellar contract extend --id <CONTRACT_ID> --ledgers-to-extend 1000 --source alice --network testnet --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.