Skip to main content
This guide will help you get started with Towns Protocol React SDK. You’ll learn how to:
  1. Install the React SDK
  2. Set up the necessary providers
  3. Connect to Towns
  4. Create a space
  5. Send your first message

Installation

You can start a new Towns project in two ways: The easiest way to get started is using create-towns-protocol-app and follow the instructions in the terminal. This will set up a new React project with all the necessary dependencies and configurations.
By default, this will create a new app using the Towns Playground template - a full-featured example application that demonstrates Towns’s Protocol capabilities.

Manual Installation

If you prefer to add the React SDK to an existing project, install the required dependencies:
Then, add the vite-plugin-node-polyfills to your vite.config.ts:
vite.config.ts

Setting Up Providers

Towns requires a few providers to be set up at the root of your application:
  1. WagmiProvider - For Web3 wallet connection (recommended)
  2. TownsSyncProvider - For interacting with Towns Protocol
Here’s how to set them up:
App.tsx
If you need any assistance with setting up Wagmi, check out the Wagmi Getting Started Guide.

Connecting to Towns Protocol

You can connect to Towns using either a Web3 wallet (recommended) or a bearer token. You can use the following networks:
  • omega - The Towns mainnet, uses Base as the EVM chain
  • gamma - The Towns testnet, uses Base Sepolia as the EVM chain
We recommend using gamma as a starting point.
You can use other gamma clients like Towns (gamma) or the Towns Playground to help you inspect messages on the gamma network.

Using a Web3 Wallet

You’ll need to use getEthersSigner to get the signer from viem wallet client. Towns SDK uses ethers under the hood, so you’ll need to convert the viem wallet client to an ethers signer.You can get the getEthersSigner function from Wagmi docs.

Using a Bearer Token

You can connect to Towns using a pre-existing identity. This allows you to read and send messages, but you won’t be able to create spaces or channels (on-chain actions).
If you have a Towns account, you can get your bearer token from there. Type /bearer-token in any conversation to get your token.

Creating a Space

Once connected, you can start interacting with Towns. Here’s how to create a space:
You can only create a space with a Web3 wallet. If you’re using a bearer token, you can’t create spaces.

Sending Your First Message

With the space created, we can send a message to the #general channel. Here’s how to create a form
Add the ChatApp component to your app and you’re ready to start chatting!

Next Steps

Now that you have the basics set up, you can: Check out our Playground template for a full-featured example application.