> For the complete documentation index, see [llms.txt](https://tivet.gitbook.io/tivet-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tivet.gitbook.io/tivet-docs/getting-started/actor-sdk.md).

# Actor SDK

Tivet Actors have built-in RPC, state, and events — the easiest way to build modern applications.

### Usage

Make sure you've installed the Tivet CLI.

```
# Create project
tivet init

# Deploy actor
tivet deploy
```

See the setup guide for more information.

### Example

```
import { Actor } from "@tivet-fun/actor";
import type { Rpc } from "@tivet-fun/actor";

// Durable state for the counter (https://tivet.fun/docs/state)
interface State {
	count: number;
}

export default class Counter extends Actor<State> {
	// Create the initial state when the actor is first created (https://tivet.fun/docs/state)
	override _onInitialize(): State {
		return { count: 0 };
	}

	// Listen for state changes (https://tivet.fun/docs/lifecycle)
	override _onStateChange(newState: State): void | Promise<void> {
		// Broadcast a state update event to all clients (https://tivet.fun/docs/events)
		this._broadcast("count", newState.count);
	}

	// Expose a remote procedure call for clients to update the count (https://tivet.fun/docs/rpc)
	increment(_rpc: Rpc<Counter>, count: number): number {
		this._state.count += count;
		return this._state.count;
	}
}
```
