Contract Lifecycle
To manage the lifecycle of a Stellar smart contract using the CLI, follow these steps:
- Create an identity for Alice:
stellar keys generate alice -q
- Fund the identity:
stellar keys fund alice
- 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.
- Initialize the contract:
stellar contract invoke --id <CONTRACT_ID> --source alice --network testnet -- initialize --param1 value1 --param2 value2
- Invoke a contract function:
stellar contract invoke --id <CONTRACT_ID> --source alice --network testnet -- function_name --arg1 value1 --arg2 value2
- 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.
- 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.
Guides in this category:
ποΈ Contract Lifecycle
Manage the lifecycle of a Stellar smart contract using the CLI
ποΈ Deploy a contract from installed Wasm bytecode
Deploy an instance of a compiled contract that is already installed on the network
ποΈ Deploy the Stellar Asset Contract for a Stellar asset
Deploy an SAC for a Stellar asset so that it can interact with smart contracts
ποΈ Extend a deployed contract instance's TTL
Use the CLI to extend the time to live (TTL) of a contract instance
ποΈ Extend a deployed contract's storage entry TTL
Use the CLI to extend the time to live (TTL) of a contract's persistent storage entry
ποΈ Extend a deployed contract's Wasm code TTL
Use Stellar CLI to extend contract's Wasm bytecode TTL, with or without local binary
ποΈ Install and deploy a smart contract
Combine the install and deploy commands in the Stellar CLI to accomplish both tasks
ποΈ Install Wasm bytecode
Use the Stellar CLI to install a compiled smart contract on the ledger
ποΈ Payments and Assets
Send XLM, stellar classic, or a soroban asset using the Stellar CLI
ποΈ Restore an archived contract using the Stellar CLI
Restore an archived contract instance using the Stellar CLI
ποΈ Restore archived contract data using the Stellar CLI
Restore archived contract storage entries using Stellar CLI