Hi there! This is the third post of the "Deep Dive into Soroban-CLI" series where we'll explore the soroban-cli in depth. Soroban-CLI is a command-line tool for interacting with soroban smart contracts on the Stellar network. Soroban-CLI provides a set of subcommands that can be used to perform various tasks related to smart contract development and deployment on the Stellar network.
In this post i will explaining
soroban serve and
soroban events subcommands.
soroban serve Subcommand
soroban serve subcommand is used to launches a local development server for soroban web app.It's useful for a few reasons:
- Rapid testing - You can quickly test changes to your app's intents, dialogs, etc. by refreshing the browser
- Local work - No need to deploy your app to a staging/production server every time you make a change
- Live reload - The server will automatically reload when you make changes to your app's code, so you see updates immediately
It will use port 8000, makes sure no service running on port 8000.
soroban events Subcommand
soroban events subcommand is used to watches for events on a blockchain from a deployed soroban smart contract. It allows you to:
- See your soroban smart contract events on the blockchain.
- Get details about each event like the event name, parameters, and contract hash, ledger.
This is useful for:
- Monitoring your smart contracts activity and usage
- Checking for errors or issues with your smart contracts
- Debugging by watching for specific events
soroban events --rpc-url <RPC_URL> --start-ledger <START_LEDGER> --cursor <CURSOR>
Usage Example :
Before we can use the
soroban events command to check events on the network i will demonstrating soroban events contract example from soroban-example github repo. Build that contract using this command :
cargo build --target wasm32-unknown-unknown --release
Then deploy that contract to Futurenet using this command :
$ soroban contract deploy --wasm /workspace/soroban-quest/soroban-examples/target/wasm32-unknown-unknown/release/soroban_events_contract.wasm --rpc-url https://rpc-futurenet.stellar.org:443 success success dc1d42101e4daa1f70bc7d79610c59e1e5df17b45aeec3a94904b352bcb39083
Invoke the deployed contract using this command :
$ soroban contract invoke \ > --rpc-url https://rpc-futurenet.stellar.org:443/ \ > --id dc1d42101e4daa1f70bc7d79610c59e1e5df17b45aeec3a94904b352bcb39083 \ > --fn increment success 1
Last we will see events created by that contract using this command :
$ soroban events --rpc-url https://rpc-futurenet.stellar.org:443/ --start-ger 518086 Event 0002225291275538432-0000000000 [CONTRACT]: Ledger: 518116 (closed at 2023-03-20T08:11:12Z) Contract: 0xdc1d42101e4daa1f70bc7d79610c59e1e5df17b45aeec3a94904b352bcb39083 Topics: Symbol(StringM(COUNTER)) Symbol(StringM(increment)) Value: U32(1) Latest Ledger: 518127
We should see events from our events contract showing ledger time the contract
increment function invoked, contract hash, parameters used, type and value of
COUNTER, and Latest ledger of the rpc network used.
soroban serve subcommand is used to launches a local development server for soroban web app. The
soroban events subcommand is used to watches for events on a blockchain from a deployed soroban smart contract. I will explain the other main subcommands in the next post of this series. Happy Sorobaning!
Top comments (0)