Skip to main content

Create And Update Spaces

This section covers how to create and update spaces on the Subsocial blockchain.

Create A Space#

substrateApi.tx.spaces.createSpace(parentIdOpt, handleOpt, content, permissionsOpt)
ParamsDescription
parentIdOptdon't use now.
handleOptdisabled now.
contentIpfsContent is a function that returns a substrate like implementation for enum { IPFS: "CID of your content"}.
permissionsadvanced options.

Example:

import { IpfsContent } from "@subsocial/types/substrate/classes"
...
const cid = await ipfs.saveContent({
about: 'Subsocial is an open protocol for decentralized social networks and marketplaces. It`s built with Substrate and IPFS',
image: 'Qmasp4JHhQWPkEpXLHFhMAQieAH1wtfVRNHWZ5snhfFeBe', // ipfsImageCid = await api.subsocial.ipfs.saveFile(file)
name: 'Subsocial',
tags: [ 'subsocial' ]
})
const tx = substrateApi.tx.spaces.createSpace(
null,
null,
IpfsContent(cid),
null
)
...

Update A Space#

substrateApi.tx.spaces.updateSpace(spaceId: AnySpaceId, update: SpaceUpdateType)
ParamsDescription
spaceIdID of the current space.
updatefields available to be updated.

Update properties

PropertiesDescription
handle?if enabled. A handle is an alias for a space ID.
content?IpfsContent is a function that returns a substrate like implementation for enum { IPFS: "CID of your content"}.
hidden?boolean, if space is hidden from other users.
permissions?advance opt.

Example:

import {
IpfsContent,
OptionBool,
SpaceUpdate
} from "@subsocial/types/substrate/classes"
...
const cid = await ipfs.saveContent({
about: 'Subsocial is an open protocol for decentralized social networks and marketplaces. It`s built with Substrate and IPFS',
image: 'Qmasp4JHhQWPkEpXLHFhMAQieAH1wtfVRNHWZ5snhfFeBe',
name: 'Subsocial updated', // updated field
tags: ['subsocial']
})
const update = new SpaceUpdate({
content: IpfsContent(cid),
hidden: OptionBool(true),
})
const tx = substrateApi.tx.spaces.updateSpace('1', update)
...

๐Ÿ†ƒ AnySpaceId: SpaceId | BN

๐Ÿ†ƒ SpaceUpdateType: { content: OptionContent, handle: OptionOptionText, hidden: Option<bool>, permissions: Option<Option<SpacePermissions >> }

๐Ÿ…ธ SpaceUpdate

OptionBool