Fetching messages

Aleph SDK help you to fetch every kind of messages with many parameters

Messages can be fetched over the SDK by using their Get function. Each message type required different parameters to be fetched. Refer to their dedicated pages for more details.

for a generic way to fetch Aleph messages use the GetMessage and GetMessages methods from Any.

Post example

Let's say we want to get some Post messages. So, first, we need to import the Post declaration to access the Get function.

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

A basic get can be performed like this:

(async() => {
	const fetched = await post.Get({
		types: 'test', // Message type of the post you want.
		pagination: 10, // Message per pages you want.
		page: 1, // Requested page.
		APIServer: 'https://api2.aleph.im' // Target API server to use.
	})
})()
The return value of the call
{ 
  posts: [ { ... }, { ... }, { ... }], 
  pagination_page: 1,
  pagination_total: 190,
  pagination_per_page: 10,
  pagination_item: 'posts'
 }

More details on Post here.

Aggregate example

Let's say we want to get keys-values associated with an account. So, first, we need to import the Aggregate declaration to access the Get function.

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

A basic get can be performed like this:

(async() => {
	const fetched = await aggregate.Get({
		addresses: account.address, // Accounts address that own the aggregates.
		APIServer: 'https://api2.aleph.im' // Target API server to use.
	})
})()
The return value of the call
{
    key1: { a: 'aleph', b: [ 'ETH', 'AVAX' ] },
    key2: { a: 1895 }
}

More details on Aggregate here.

Store example

Let's say we want to get file content. So, first, we need to import the Store declaration to access the Get function.

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

A basic get can be performed like this:

(async() => {
	const fetched = await store.Get({
            fileHash: "QmQkv43jguT5HLC8TPbYJi2iEmr4MgLgu4nmBoR4zjYb3L", // hash of the file.
            APIServer: DEFAULT_API_V2, // Target API server to use.
        });
})()
The return value of the call
<Buffer 54 68 69 73 20 69 73 20 6a 75 73 74 20 61 20 74 65 73 74 2e>
new TextDecoder().decode(fetched) = "This is just a test";

More details on Store here.

Last updated