Create

Usage

Import the Post declaration to interact with the Publish function and the Item type to choose your storage location.

import { messages } from 'aleph-sdk-ts';
import { ItemType } from 'aleph-sdk-ts/dist/messages/message';

// Or used optimized import

import { Publish as publishPost } from 'aleph-sdk-ts/dist/messages/post';

Then call the Publish function, with the required parameters as follow:

(async () => {
  await publishPost({
    account: account,
    postType: 'mytype',
    content: {'body': 'test post for gitbook'}, //'tags': ['Test'] can be add for filtering
    channel: 'TEST',
  })
})();

Parameters

ParameterDescription

Account - required Account

The account that will sign the message.

postType - required string

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

content - required object

The value to associate with your key.

channel - required string

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

storageEngine - optional ItemType

Storage engine to use, either Aleph storage, IPFS, or inline.

APIServer - optional string

The API server endpoint that is used to carry the request to Aleph's network.

ref - optional string or ChainRef

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

address - optional string

With a configured security key, your message will be published for this given address.

ChainRef Object
{
    chain: string; 
    channel? : string;
    item_content: string;
    item_hash: string;
    item_type: string;
    sender: string;
    signature: string;
    time: number;
    type: MessageType.post;
}

post_content has a limit size of just under 50Kb, for a bigger document size, use Aleph Storage or IPFS (The SDK will perform the change automatically).

To save more significant documents, the content should be stored in a Store Item and then specify a ref for the item in a Post.

Return

Return value Publish Post
{
  chain: 'ETH',
  sender: '0xA742a7944641a3deD9fd5f8071f6002E8C91a1c4',
  type: 'POST',
  channel: 'TEST',
  confirmed: false,
  signature: '0x78372344b43e655ee95087b16764145221a2fe7a01295ea80c3190f8a5a68a1550929e94d8f379aa8ddc26e6b835defff2babef781274c1abad5c55342eb54cf1b',
  size: 0,
  time: 1667829566.209,
  item_type: 'inline',
  item_content: '{"type":"mytype","address":"0xA742a7944641a3deD9fd5f8071f6002E8C91a1c4","content":{"body":"test post for gitbook"},"time":1667829566.209}',
  item_hash: 'c4520d0c041ff49df839180fd69757999b6a6ad441bd1b269121613a9e1f338a',
  content: {
    type: 'mytype',
    address: '0xA742a7944641a3deD9fd5f8071f6002E8C91a1c4',
    content: { body: 'test post for gitbook' },
    time: 1667829566.209,
    ref: undefined
  }
}

This message can be retrived here!

Last updated