Create a post

Call the .submit() function to create a Post

Returns

The post object that was just created.

Tips Pass a ref in the optional object parameter and/or tags in your content to take full advantage of the filtering abilities later on.

Usage

import { posts } from 'aleph-js'

await posts.submit(address, post_type, content)

// Or with optional parameters
await posts.submit(address, post_type, content, { channel: channel, account: account})

Required parameters

ParameterDescription

address - string

Address the Post should be associated with or the address that submitted the Post.

post_type - string

A lowercase string of your choice for the item_content.type of the post message. ex: amend,blog, chat, comment

content - object

The content object to save to the item_content.content of the post message.

If tags are passed within the object, they can be searched for later on.

Optional parameters

In addition to the required parameters above, an object of optional parameters can be passed following the content like so:

posts.submit(address, post_type, content,{api_server: "https://api2.aleph.im"})

  • api_server - string

    Default: "https://api1.aleph.im"

    Target API server

  • ref - string

    Default: null

    A searchable reference string of your choice to save to the item_content.ref. Can be the reference to another post, an address, transaction hash, etc.

  • chain - string

    Default: null

    The chain used by the sender's account. Value can be NULS2, ETH, DOT, CSDK, SOL, AVAX

  • channel - string

    Default: null

    Channel of the message. Ideally, an application would decide and use one channel.

  • inline - boolean

    Default: true

    Should the message be stored as a separate file or inserted inline?

    ℹī¸ Set it to false for data that could fall under GDPR.

  • storage_engine - string either "ipfs" or "storage"

    Default: "storage"

    Storage engine to use. Possible values: storage, ipfs

  • account - Account

    Default: null

    Account to use for signing.

    ℹī¸ Needed if you want to send the message. Without it, it is a dry run.

Example: Create post

CREATE POST
import { posts } from 'aleph-js'

await posts.submit(
  account.address,
  'mytype',
  {'body': 'test'},
  {
    'account': account,
    'channel': 'TEST',
    'api_server': 'https://api2.aleph.im'
  }
 )
RESPONSE
{ 
  chain: 'NULS2',
  channel: 'TEST',
  sender: 'NULSd6HgcLR5Yjc7yyMiteQZxTpuB6NYRiqWf',
  type: 'POST',
  time: 1582555614.466,
  item_type: 'inline',
  item_content: '{
    "type":"mytype",
    "address":"NULSd6HgcLR5Yjc7yyMiteQZxTpuB6NYRiqWf",
    "content":{"body":"test"},
    "time":1582555614.466
  }',
  item_hash:'b546f70573a1a91a35a39dbacea0bbfe50847337dcbd995323994535847a6519',
  signature: 'HGnCVb6Rnck5l/BfP93zR3/dvgVToK1yRiPTQrCZjKA/eMiUZwMkaSQFb/FMLvENTtZX804KRERGZxoxU1lEip0=' 
}

Last updated