# How to run operations · Chromia Docs (concept)

> Execute transactions with chr tx commands

Source: https://docs.chromia.com/build/cookbook/cli/run-operations/

# How to run operations

On this page

* [Prerequisites](#prerequisites)
* [Basic operation workflow](#basic-operation-workflow)
* [Step 1: Verify your node is running](#step-1-verify-your-node-is-running)
* [Step 2: Generate a key pair (if you haven't already)](#step-2-generate-a-key-pair-if-you-havent-already)
* [Step 3: Run a simple operation](#step-3-run-a-simple-operation)
* [Operation methods overview](#operation-methods-overview)
* [Local operations (development)](#local-operations-development)
* [Remote operations (deployed dapps)](#remote-operations-deployed-dapps)
* [Operation parameters](#operation-parameters)
* [Basic parameter types](#basic-parameter-types)
* [Advanced parameter types](#advanced-parameter-types)
* [Transaction options](#transaction-options)
* [Awaiting confirmation](#awaiting-confirmation)
* [Making transactions unique](#making-transactions-unique)
* [Using different key files](#using-different-key-files)
* [Testing against deployed dapps](#testing-against-deployed-dapps)
* [Testnet operations](#testnet-operations)
* [Common operation patterns](#common-operation-patterns)
* [Book management](#book-management)
* [House management](#house-management)
* [Company management](#company-management)
* [Library management](#library-management)
* [Error handling](#error-handling)
* [Common error scenarios](#common-error-scenarios)
* [Debugging operations](#debugging-operations)
* [Next steps](#next-steps)

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](https://docs.chromia.com/get-started/installation/)
* [Rell dapp project created](https://docs.chromia.com/build/cookbook/cli/create-rell-dapp/) with local node running OR access to a deployed dapp
* [Key pair generated](https://docs.chromia.com/build/cli/commands/keygen/) for signing transactions

## Basic operation workflow

### Step 1: Verify your node is running

Terminal

```
# Check if local node is responding
curl http://localhost:7740
```

### Step 2: Generate a key pair (if you haven't already)

Terminal

```
# 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

Terminal

```
# Test a basic operation (--local is the default)
chr tx --secret .chromia/chromia_key create_book "ISBN001" "Chromia 101" "Alice Johnson"
```

Expected output:

Plain text

```
Transaction submitted successfully
Transaction hash: 0x1234567890abcdef...
```

**Note**: You can also use the Blockchain RID explicitly:

Terminal

```
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)

Terminal

```
# 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)

Terminal

```
# 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](https://docs.chromia.com/build/cli/commands/tx/):

### Basic parameter types

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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

Terminal

```
# 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:

1. [Run queries](https://docs.chromia.com/build/cookbook/cli/run-queries/) to verify your operations worked correctly
2. [Run tests](https://docs.chromia.com/build/cookbook/cli/run-tests/) to automate operation testing
3. [Deploy your dapp](https://docs.chromia.com/build/cli/commands/deployment/) to make operations available publicly
4. [Use multi-signature transactions](https://docs.chromia.com/build/cli/commands/multi-signature/) for advanced security requirements

[View this page on docs.chromia.com](https://docs.chromia.com/build/cookbook/cli/run-operations/)Content mirrored from the live docs
