Writing to the network requires a blockchain account which will serve as the referenced account on the resource generated.
Posting to the network is done in two steps:
Connect a blockchain account
Create a resource
1. Connect a blockchain account
The aleph typescript SDK currently supports the following chains:
Ethereum
Solana
Substrate
Whether you connect to an existing blockchain account or create a new one, the account returned by the library is an object having:
an address
a publicKey
a wallet object
➡️ With an existing blockchain account
You can connect any existing blockchain account by using the ImportAccount function and passing in either the private key or the mnemonics of the account depending on the chain used.
More details on importing and creating an account are available here.
2. Create a resource
import { post } from'aleph-sdk'import { ethereum } from'aleph-sdk/accounts'import { StorageEngine } from"aleph-sdk-ts/messages/message"(async() => {// Import account from the correct chain to post to Aleph account =awaitethereum.ImportAccountFromMnemonic('<YOUR PASSPHRASE HERE>')awaitpost.Publish({ account: account, postType:'mytype', content: {'body':'test post written on Aug 17th'}, channel:'TEST', APIServer:'https://api2.aleph.im', inlineRequested:true, storageEngine:StorageEngine.STORAGE }) })()
🎉 A Message object, with a POST type, has been created and is returned.
{ chain:"<YOUR ACCOUNT CHAIN>", channel:"TEST", confirmed:false, item_content: "{\"type\":\"mytype\",\"address\":\"<YOUR ADDRESS APPEAR HERE>\",\"content\":{\"body\":\"test post written on Aug 17th\"},\"time\":1636137569.869}",
item_hash:"8671a9bb4dac018a0bd8b5c56ac883fd551f43af2b01d34e60215a8419d555b0", item_type:"INLINE", sender:"<YOUR ADDRESS APPEAR HERE>", signature: "0x0338f9c3ae1eb4715a923094f4ee5459a3131e54b393b9640c137f11cb5fc8c131299723fb19c2cdd971ee60c6cd68bb9643c93d92e918e8be1ec787657da9631b",
size:0, time:1636137569.869, type:"POST"}
All posts, aggregates and stores resources created in Aleph are inherently Message Objects. Depending on the type of resource created, the item_content object keys will differ.
3. Going further
Learn more about how you can create, update and query Post, Aggregate and Store objects.