Create

Call the .Publish function to create an aggregate of a key-value pair for an account.

Usage

Import the Aggregate 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 publishAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';

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

(async () => {
  await publishAggregate({
    account: account,
    key: 'test_key',
    content: {'a': 1, 'my_array': ["ETH", "AVAX"] },
    channel: "TEST",
  })
})();

Parameters

ParameterDescription

Account - required Account

The account that will sign the message.

key - required string

The key under your data will be stored.

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.

address - optional string

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

Return

Return value Publish Aggregate
{
  chain: 'ETH',
  channel: 'TEST',
  sender: '0xb45442cEC65e23696bA3a2f78059362d4022bEC5',
  type: 'AGGREGATE',
  confirmed: false,
  signature: '0xbf849b6276d9f750e049a4cb999c6d8694759a2cd7d09c75d683b359ff66b72e320adf0818bba55e6959ff49d2c2086a77f5ae0e23c022b3c9daf8e979a460d81c',
  size: 0,
  time: 1666727318.272,
  item_type: 'inline',
  item_content: '{"address":"0xb45442cEC65e23696bA3a2f78059362d4022bEC5","key":"key1","time":1666727318.272,"content":{"a":"aleph","b":["ETH","AVAX"]}}',
  item_hash: 'f3577acc25d8d1d0167ea4eb06a2c7f90076653196945826c091b625dd3a7a22',
  content: {
    address: '0xb45442cEC65e23696bA3a2f78059362d4022bEC5',
    key: 'key1',
    time: 1666727318.272,
    content: { a: 'aleph', b: [Array] }
  }
}

This message can be retrived here!

Full example

import { ItemType } from 'aleph-sdk-ts/dist/messages/message';
import { Publish as publishAggregate } from 'aleph-sdk-ts/dist/messages/aggregate';

(async () => {
  const res = await publishAggregate({
    account: account,
    key: 'test_key',
    content: {'a': 1, 'my_array': ["ETH", "AVAX"] },
    channel: "TEST",
    storageEngine: ItemType.inline,
    inlineRequested: true,
    APIServer: "https://api2.aleph.im"
  })

  console.log(res);
})();

Last updated