Skip to main content

Synopsis

cowboy actor new <name>

Behavior

  1. Create a directory actors/<name>/.
  2. Write actors/<name>/main.py with the actor template (see below).
  3. Print the created file path and next steps.

Actor Template

class Actor:
    """A Cowboy actor deployed on-chain."""

    def __init__(self):
        self.counter = 0

    def increment(self):
        self.counter += 1
        return self.counter

    def get_count(self):
        return self.counter
This template:
  • Defines a class named Actor (the entry point the VM looks for).
  • Has simple state (self.counter) to demonstrate persistence.
  • Has two handlers: increment (write) and get_count (read).
  • Follows the determinism constraints of the Cowboy VM (no imports, no I/O, no randomness).

Example

$ cowboy actor new counter
Created actor:
  actors/counter/main.py

Next steps:
  # Edit the actor
  vim actors/counter/main.py

  # Deploy to local validator
  cowboy actor deploy --code actors/counter/main.py

Edge Cases

  • Name collision — If actors/<name>/ already exists, print an error and exit. Do not overwrite.
  • No actors/ directory — Create actors/ if it doesn’t exist.
  • Invalid name — Actor names must be valid directory names. Reject names containing /, .., or whitespace.

Testing

# Create actor
cowboy actor new myactor
cat actors/myactor/main.py   # Should contain the template

# Verify collision detection
cowboy actor new myactor      # Should print error, not overwrite

# Deploy and test (requires running validator)
cowboy actor deploy --code actors/myactor/main.py