How to run operations
Operations are transactions that modify blockchain state by creating, updating, or deleting data. This guide shows you how to use operations during development and testing.
Prerequisites
- Chromia CLI installed
- Rell dapp project created with local node running OR access to a deployed dapp
- Key pair generated for signing transactions
Basic operation workflow
Step 1: Verify your node is running
# Check if local node is responding
curl http://localhost:7740
Step 2: Generate a key pair (if you haven't already)
# Generate a new key pair
chr keygen
# This creates .chromia/chromia_key and .chromia/chromia_key.pubkey
# The default key ID is 'chromia_key'
Step 3: Run a simple operation
# Test a basic operation (--local is the default)
chr tx --secret .chromia/chromia_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
Expected output:
Transaction submitted successfully
Transaction hash: 0x1234567890abcdef...
Note: You can also use the Blockchain RID explicitly:
chr tx --blockchain-rid <BlockchainRID> --secret .chromia/chromia_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
Replace <BlockchainRID>
with the actual Blockchain RID from your node output. You can find this in the node startup
output as: Blockchain RID: FC17B67D66F6F35A5D8B75ED3F83AE222FB8C8FCA241624F06285150F10C6BAC
Operation methods overview
Local operations (development)
# Default local operation
chr tx --secret .chromia/chromia_key create_house "123 Main St" 4 200
# Explicit blockchain RID (equivalent to --local for development)
chr tx --blockchain-rid <BlockchainRID> --secret .chromia/chromia_key create_house "123 Main St" 4 200
# Wait for transaction confirmation
chr tx --secret .chromia/chromia_key --await create_house "123 Main St" 4 200
Remote operations (deployed dapps)
# Operation on deployed dapp using network and blockchain name
chr tx --network testnet --blockchain my_rell_dapp --secret .chromia/chromia_key create_company "TechCorp" "456 Business Ave"
Operation parameters
When you create operations that accept parameters, use this syntax based on the official CLI documentation:
Basic parameter types
# String parameters (quoting optional for simple strings)
chr tx --secret .chromia/chromia_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
# Strings with spaces (require quotes)
chr tx --secret .chromia/chromia_key create_company "TechCorp Inc"
# Integer parameters
chr tx --secret .chromia/chromia_key create_house "123 Main St" 4 200
# Multiple parameters example
chr tx --secret .chromia/chromia_key create_library "Central Library" "Downtown" 1000
Advanced parameter types
# Byte array parameters (public keys, hashes, etc.)
chr tx --secret .chromia/chromia_key transfer_tokens 'x"0373599a61cc6b3bc02a78c34313e1737ae9cfd56b9bb24360b437d469efdf3b15"' 'x"0373599a61cc6b3bc02a78c34313e1737ae9cfd56b9bb24360b437d469efdf3b15"' 100
# Dictionary/map parameters
chr tx --secret .chromia/chromia_key update_user_metadata '["key1": "value1", "key2": "value2"]'
# Array parameters
chr tx --secret .chromia/chromia_key batch_create_users '["Alice", "Bob", "Charlie"]'
Transaction options
Awaiting confirmation
# Wait for transaction to be confirmed (recommended for important operations)
chr tx --secret .chromia/chromia_key --await create_book "ISBN001" "Chromia 101" "Alice Johnson"
Making transactions unique
# Add a NOP to make transaction hash unique (useful for repeated operations)
chr tx --secret .chromia/chromia_key --nop create_book "ISBN001" "Chromia 101" "Alice Johnson"
Using different key files
# Use a specific key file
chr tx --secret /path/to/my_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
# Use key by ID (if configured in .chromia/config)
chr tx --secret my_custom_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
Testing against deployed dapps
Testnet operations
# Basic operation on deployed dapp
chr tx --network testnet --blockchain my_rell_dapp --secret .chromia/chromia_key create_company "TechCorp" "456 Business Ave"
# Operation with parameters on deployed dapp
chr tx --network testnet --blockchain my_rell_dapp --secret .chromia/chromia_key create_house "123 Main St" 4 200
Common operation patterns
Book management
# Create a new book
chr tx --secret .chromia/chromia_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
# Update book information
chr tx --secret .chromia/chromia_key update_book "ISBN001" "Chromia 101: Updated Edition"
# Delete book record
chr tx --secret .chromia/chromia_key delete_book "ISBN001"
House management
# Create a new house
chr tx --secret .chromia/chromia_key create_house "123 Main St" 4 200
# Update house details
chr tx --secret .chromia/chromia_key update_house "123 Main St" 5
# Register house ownership
chr tx --secret .chromia/chromia_key register_house_owner "123 Main St" "Bob Smith"
Company management
# Create a new company
chr tx --secret .chromia/chromia_key create_company "TechCorp" "456 Business Ave"
# Update company information
chr tx --secret .chromia/chromia_key update_company "TechCorp" "789 Innovation Blvd"
# Add employee to company
chr tx --secret .chromia/chromia_key add_employee "TechCorp" "Carol Davis"
Library management
# Create a new library
chr tx --secret .chromia/chromia_key create_library "Central Library" "Downtown"
# Add book to library
chr tx --secret .chromia/chromia_key add_book_to_library "Central Library" "ISBN001" 3
# Check out book
chr tx --secret .chromia/chromia_key checkout_book "ISBN001" "David Wilson"
Error handling
Common error scenarios
# Operation fails due to insufficient permissions
chr tx --secret .chromia/chromia_key admin_only_operation
# Error: Operation requires admin privileges
# Operation fails due to invalid parameters
chr tx --secret .chromia/chromia_key create_book "" "Chromia 101" "Alice Johnson"
# Error: ISBN cannot be empty
# Operation fails due to duplicate key
chr tx --secret .chromia/chromia_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
chr tx --secret .chromia/chromia_key create_book "ISBN001" "Another Book" "Bob Smith"
# Error: Book with ISBN 'ISBN001' already exists
Debugging operations
# Use --await to see detailed error messages
chr tx --secret .chromia/chromia_key --await problematic_operation
# Check transaction status
chr query get_transaction_status "string:tx_hash->0x1234567890abcdef..."
Next steps
After mastering operations:
- Run queries to verify your operations worked correctly
- Run tests to automate operation testing
- Deploy your dapp to make operations available publicly
- Use multi-signature transactions for advanced security requirements