Skip to main content

Create And Update Comments

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

Create a comment​

import { IpfsContent } from '@subsocial/types/substrate/classes'

const substrateApi = await api.substrateApi

substrateApi.tx.posts.createPost(spaceIdOpt, { Π‘omment }, IpfsContent("CID of your content"))
PropertiesDescription
parentId?ID of the post or comment that was replied to.
rootPostId?ID of the original post.

Comments directly under a post will have the same parentId and rootPostId.

Create a comment below a post​

import { IpfsContent } from "@subsocial/api/substrate/wrappers"

...
const cid = await api.ipfs.saveContent({
body: 'Keep up the good work!'
})

const substrateApi = await api.substrateApi

const tx = substrateApi.tx.posts.createPost('1', { Comment: { parentId: null, rootPostId: '1'}}, IpfsContent(cid))

...

Create a reply to a comment​

import { IpfsContent } from "@subsocial/api/substrate/wrappers"

...
const cid = await api.ipfs.saveContent({
body: 'Agree' //replied
})

const substrateApi = await api.substrateApi

const tx = substrateApi.tx.posts.createPost('1', { Comment: { parentId: '2', rootPostId: '1'}}, IpfsContent(cid))
...

Update A Comment​

For updating comments use post methods.