Towns contracts are composable, extensible, and upgradable. Use them to set community rules, define custom business models, and craft your own vision of the Towns protocol.
During the alpha period, the Towns smart contracts are deployed on Sepolia. At beta, they will be deployed on the Ethereum mainnet.
Each Towns space also has its own Space Contract.
Towns uses a factory model to create and manage spaces. Each space gets deployed to its own contract address.
<createSpace> function is the heart of the Towns space factory. It requires an ID generated from the given chat protocol. The space creation process includes the following steps: Map the space’s network ID to its Towns address
- Set permissions
- Mint the space token
- Set the space owner and entitle them to the space token
- Deploy the space contract, including entitlement modules
<addOwnerPermissions> function adds a permission to the owner role for a given space.
<getOwnerPermissions> function returns all of the permissions for the owner of a given space.
<updateImplementations> function allows for upgrading the underlying space logic in entitlement modules for a given space while retaining state. The space has control to decide who can grade implementation for its own space.
Each Towns community is powered by its space contract. The space is a key concept in Towns: it represents a community’s identity and facilitates governance. You can think of spaces as composable, on-chain primitives for communities.
<createChannel> function creates a channel within a given space. It requires an ID generated from the given chat protocol.
<setChannelAccess> sets whether a channel is enabled or disabled. A disabled channel would deactivate the channel for its users.
<createRole> function creates a role within a given space.
<getRole> function returns a role within a given space by ID.
<removeRole> removes a role within a given space.
<addPermissionToRole> function sets a permission to a role within a given space.
<getPermissionToRole> gets a permission from a role within a given space.
<removePermissionToRole> function removes a permission from a role within a given space.
<isEntitled> (see next section)
<upgradeTo> function sets a new implementation address for the space factory itself.
Entitlements help you control access and manage user permissions. For more information, see entitlements.
<SpaceOwner.sol> contract is a convenience contract for minting and owning a space as an NFT.
Towns smart contracts are upgradable, alleviating a common pain point of blockchain development.
- Implementation addresses: Each new contract version has a new implementation address; the previous version is not affected.
- State preserved: Space “state” is preserved with each upgrade — you won’t need to redeploy contracts or redeploy spaces to Dendrite.
- Opt in: As upgrades become available, space owners can opt in or skip the upgrade. In this way, upgradability helps to ensure that communities retain ownership and control of their Towns spaces.
Coming soon! The Towns DAO will govern all parts of the smart contracts and protocol. Documentation of governance contracts will be available in the future.
Coming soon! The Towns node manager contract defines rules and provides functions for managing nodes, including registering, validating, and checkpointing.
Coming soon! Towns on Etherscan.