PostClient
Discover how the PostClient class works
Index
How to instantiate an object of the PostClient class?
The PostClient class provides the necessary functionality for the user to create social interactions within the platform. To understand what this implies, a look at the Concepts section may be necessary to understand the lifecycle of a Post. In summary, the basic functionalities of the PostClient class include the ability to create or delete Posts and to create PostReply, which are offers to exchange under the original Post.
The code snippets are presented in a context where React is used, but any framework for building a Single Page Application (SPA) is suitable.
Once the object is initialized, all the trading functionalities provided by the SDK will be accessible. In the above example, some aspects of this object instance can be noted. The parameter provided for the instance is as follows:
It is the key to request in order to interact with the NFT Trader platform. You can request it here.
Before we begin, the signedMessage
In order to correctly interact with the methods made available by the PostClient class, it is important to note that in order to properly validate the user's wallet when performing various operations such as creating and deleting Posts or PostReply, a parameter called signedMessage
must be provided. This parameter can be obtained by signing a specific message provided by the PostClient class.
To sign the message, the personal_sign
method provided by the current provider being used can simply be used. In the following example, this is how the message could be encoded using the PostClient class.
Create a Post
In order to create a Post, the PostClient class provides the createPost()
method. This method takes in several parameters that we will see in the example below. We will then look in detail at how to correctly configure these parameters. For the moment, let's focus on the main operations described in this pseudocode.
As described in the example, the createPost()
method allows creating a Post within the system. This operation will prompt the user to sign with their own wallet. The message to be signed and all the logic related to it are already encapsulated within the SDK, so there will be no need to manage them directly.
Parameters
On the other hand, the parameters of the createPost()
method must be composed correctly. Below we will explain how to perform this operation and provide an explanation for each required parameter.
First of all, let's analyze the signature of the createPost()
method.
post
The post
parameter is of type CreatePost
. Its structure is described here.
signedMessage
The parameter signedMessage
is of type string
. It is a message that the user must sign with their own wallet. The ways in which the user must sign the message are described here.
Delete a Post
To delete a Post, the PostClient class provides the deletePost() method. This method takes two input parameters. Let's analyze the following pseudocode in detail to understand how it works.
As described in the example, the deletePost()
method allows deleting a Post within the system. This operation will prompt the user to sign with their own wallet. The message to be signed and all the logic related to it are already encapsulated within the SDK, so there will be no need to manage them directly.
Parameters
On the other hand, the parameters of the deletePost()
method must be composed correctly. Below we will explain how to perform this operation and provide an explanation for each required parameter.
First of all, let's analyze the signature of the deletePost()
method.
id
The parameter id
is of type string
and refers to the id of the post that you want to delete.
signedMessage
The parameter signedMessage
is of type string
. It represents a message that the user must sign with their own wallet. The methods through which the user must sign the message are described here.
Create a PostReply
In order to create an offer related to a post, the PostClient class provides the createPostReply()
method. Let's analyze the following pseudocode in detail to understand how it works.
As described in the example, the createPostReply()
method allows creating a PostReply within the system. This operation will prompt the user to sign with their own wallet. The message to be signed and all the logic related to it are already encapsulated within the SDK, so there will be no need to manage them directly.
Parameters
On the other hand, the parameters of the createPostReply()
method must be composed correctly. Below we will explain how to perform this operation and provide an explanation for each required parameter.
First of all, let's analyze the signature of the createPostReply()
method.
reply
The reply
parameter is of type CreatePostReply
, the structure of which is described here. The reply is the object that contains information related to the offer.
parentId
The parentId
parameter is of type string
. It refers to the original Post to which the user is making an offer.
signedMessage
The parameter signedMessage
is of type string
. It represents a message that the user must sign with their own wallet. The ways in which the user must perform the message signature are described here.
Get Post
It is possible to obtain information about a single post using the getPost()
method provided by the PostClient
class. Let's analyze the following pseudocode to understand a possible implementation.
This method returns an object of type Maybe<Post>
. The structure of this object is described in this section.
Parameters
Let's analyze the parameters of the function starting from the method signature.
id
The parameter id is of string
type and refers to the identifier of the Post
for which one wants to obtain information.
creatorAddress
The optional parameter creatorAddress
is of type string
and refers to the address of the wallet that created the Post. It is used to ensure that the isCreator
field of the Post object returned by the method is set to true
if the creatorAddress matches the address of the wallet that created the Post.
List Posts
It is possible to obtain information about all the Posts created by users using the listPosts()
method provided by the PostClient class. The listPosts()
method can be used to build a feed page, in which all the posts created by users can be displayed. Let's analyze the following pseudocode to understand a possible implementation.
As you can see, the method listPosts()
takes in a set of parameters that determine the final outcome. The resulting object is of type ListPostResponse
and its structure can be analyzed here.
Parameters
The parameters involved are mainly the filters and the type of sorting desired. In addition, it is possible to paginate the results obtained through the use of the last two parameters. However, let's break down the method signature and thoroughly analyze the parameters accepted by the method.
filtersOptions
An object of type ListPostsFilters
. This object is used to filter the posts, so that the resulting output matches the desired characteristics.
The filtersOptions
object in turn contains the following properties:
owner
property of typestring
. It is used to filter all posts created by the indicated username or address.collections
property of typeArray<{address: string; network: Network}>
. It is used to filter all posts that contain one or more collections specified by their address and network.status
property of typePostStatusName
orPostStatus[PostStatusName]
. It is used to filter posts that have a specific status. Remember that the post statuses are described in the Post Lifecycle section.type
property of typePostTypeName
orPostType[PostTypeName]
. It is used to filter posts of a specific type. Remember that the post types are described in the Types of Posts section.typeWanted
property of typeBitmapWanted
. It is used to filter posts that have a specific sequence of assets in the wanted side. Remember that the types of assets that can be referenced in a post are described in the Post Assets section.typeOffered
property of typeBitmapOffered
. It is used to filter posts that have a specific sequence of assets in the offered side. Remember that the types of assets that can be referenced in a post are described in the Post Assets section.verified
property of typeboolean
. It is used to filter all posts that contain only verified collections.network
property of typeNetwork
. It is used to filter all posts that belong to a specific blockchain.offers
property of typenumber
. It is used to filter all posts that have at least the number of offers indicated by this filter.expirationDate
property of typenumber
. It is used to filter all posts that have an expiration date before the date indicated by this filter. The date value is expressed in seconds.includeParent
property of typeboolean
. It is used to include in theListPostResponse
object the information about the parent post for all posts classified asPostReply
.
ordersOptions
An object of type ListPostsOrders
. This object is used to sort the posts, so that the resulting output matches the desired characteristics.
The orderOptions
object in turn contains the following properties:
field
property of typestring
. It is used to indicate the type of sorting desired. Possible values arecreationDate
,expirationDate
,assetsOffered
orassetsWanted
. - sorting with the value ofcreationDate
sorts posts by creation date. - sorting with the value ofexpirationDate
sorts posts by expiration date. - sorting with the value ofassetsOffered
sorts posts by number of offered assets. - sorting with the value ofassetsWanted
sorts posts by number of wanted assets.direction
optional property of typestring
. It is used to set the sorting direction, whether it is ascending (ASC
) or descending (DESC
).
skip
A number
representing the number of posts to skip (used for the pagination).
take
A number
representing the number of posts to take (used for the pagination).
creatorAddress
A string
representing the address of the wallet owner. Used to set the isCreator
value to true
in the case a post is created by this address.
Get Post Replies
It is possible to obtain a list of offers related to a Post
through the getPostReplies()
method provided by the PostClient
class. Let's analyze the following pseudocode to see a hypothetical example of implementation.
As you can see, the method getPostReplies()
takes in a set of parameters that determine the final outcome. The resulting object is of type ListPostResponse
and its structure can be analyzed here.
Parameters
The parameters involved are mainly the type of sorting desired. In addition, it is possible to paginate the results obtained through the use of the last two parameters. However, let's break down the method signature and thoroughly analyze the parameters accepted by the method.
id
The parameter id is of string
type and refers to the identifier of the Post
parent for which one wants to obtain information related to each PostReply
linked to it.
ordersOptions
An object of type ListPostsRepliesOrders
. This object is used to sort the posts, so that the resulting output matches the desired characteristics.
field
property of typestring
. It is used to indicate the type of sorting desired. Possible values arecreationDate
orscore
. - sorting with the value ofcreationDate
sorts post replies by creation date. - sorting with the value ofscore
sorts post replies by the score.direction
optional property of typestring
. It is used to set the sorting direction, whether it is ascending (ASC
) or descending (DESC
).
Last updated