Skip to main content

Create And Update Comments

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

Post methods are used for comments.

Create a comment#

import { getSubstrateApi } from '@subsocial/api'
import { IpfsContent } from '@subsocial/types/substrate/classes'
const substrateApi = getSubstrateApi({ endpoint: substrateUrl })
substrateApi.tx.posts.createPost(spaceIdOpt, { Π‘omment }, IpfsContent("CID of your content"))

πŸ…Έ Comment

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/types/substrate/classes"
...
const cid = await ipfs.saveContent({
body: 'Keep up the good work!'
})
const tx = substrateApi.tx.posts.createPost('1', { Comment: { parentId: null, rootPostId: '1'}}, IpfsContent(cid))
...

Create a reply to a comment#

import { IpfsContent } from "@subsocial/types/substrate/classes"
...
const cid = await ipfs.saveContent({
body: 'Agree' //replied
})
const tx = substrateApi.tx.posts.createPost('1', { Comment: { parentId: '2', rootPostId: '1'}}, IpfsContent(cid))
...

Update A Comment#

For updating comments use post methods.