Publish messages

The aleph network revolves around messages

Context

Messages are requests that you can use to communicate with the Aleph services. It can allow you to save key-value content, upload file, or run programs.

Currently available Aleph messages:

Message structure

All the messages follow this based structure:

// Message info
type:    string | The type of the message, can be Post, Aggregate, Store, ...
channel: string | Channel of the message, ideally one application has one channel.
time:    float  | When the message was created.

// Sender info
sender: string | The address of the account that signed and sent the transaction.
chain:  string | The chain used by the sender: AVAX, ETH, DOT, SOL, ...

// Content
item_hash:    string      | The sha256 of the item_content field.
item_content: JSON string | The content of the message according to its type.
item_type:    string      | Where to store item_content: inline, IPFS, storage.
hash_type:    string      | The algorithm used for the item_hash.

Item_content example

Each message has a different item_content. You can find their definition on their dedicated pages.

Item_content for a Post
item_content:
  type: // Type of the Post: blog, comment, ...
  address: // The account address associated with the post.
  content: // An object containing the content of the post.
  time: // When the object where created.
  ref: // A text that is linked to this post, another post for example.
Item_content for an Aggregate
item_content:
    key: // The indexed key under the content is stored.
    address: // The account address associated with the post.
    content: // An object containing the value associated with the key.
    time: // When the object where created. 

Item_type and storage

You can choose several ways to store your data on the Aleph network.

When you are uploading a message on Aleph you can use the storageEngine param to ask the network where to store the content of your message. It can be a JSON string inside the item_content field or a database.

If your data could fall under GDPR. Set the storageEngine field to storage or ifps.

  • Storage - A non SQL database solution

  • IPFS - The famous file storage decentralised protocol.

Sending Post example

An account is required to send and signed transaction on the Aleph Network. If you need a reminder on Aleph's accounts: here.

First of all, you need to import the `messages` declaration.

import { messages } from 'aleph-sdk-ts';

Then you can choose the message type of your choice and call the Publish method:

(async() => {
	const res = await messages.post.Publish({
		account: account,
		postType: 'mytype',
		content: {'body': 'content of my post'},
		channel: 'TEST',
	})
})()
// Will return
{
  chain: 'ETH',
  sender: '0xD3b9Be2199AeB8937a0080171eed7195fd9A623F',
  type: 'POST',
  channel: 'TEST',
  confirmed: false,
  signature: '0x193e399ac7dc771ac983493b8e473609a2ec26aba5688ab5db286aa007004a36420e83405ac2f7ac0c23c39e5f19c14f5946d36005572ef8c5b59b294a19b9851c',
  size: 0,
  time: 1666629592.28,
  item_type: 'inline',
  item_content: '{"type":"mytype","address":"0xD3b9Be2199AeB8937a0080171eed7195fd9A623F","content":{"body":"content of my post"},"time":1666629592.28}',
  item_hash: '84ab3d147fff3d593e02baf89aa62900f521aaa862ec35ea098cbecef275977b',
  content: {
    type: 'mytype',
    address: '0xD3b9Be2199AeB8937a0080171eed7195fd9A623F',
    content: { body: 'content of my post' },
    time: 1666629592.28,
    ref: undefined
  }
}

All messages are listed on the Aleph Explorer. This one is here

A message's page is built following this pattern: https://explorer.aleph.im/address/<Chain-Type>/<Your-Address>/message/<Message-Type>/<Message-hash>

Last updated