Writing to the Network

Writing to the network requires a blockchain account which will serve as the account on the resource generated.
Posting to the network is done in two steps:
  1. 1.
    Connect a blockchain account
  2. 2.
    Create a resource

1. Connect a blockchain account

The aleph-client currently supports the following chains:
  • NULS 1.0 and NULS 2.0
  • Ethereum
  • Polkadot - Substrate
  • Cosmos SDK
  • Solana
Whether you connect to an existing blockchain account or create a new one, the account returned by the library is an object responding to 2 functions:
  • .get_address()
  • .get_public_key()
// Example of an account imported or created through aleph-client

➡️ With an existing blockchain account private key

You can connect any existing blockchain account by using the relevant chain module and passing in the private key or mnemonics of the account.
from aleph_client.chains.cosmos import CSDKAccount
account = CSDKAccount("<Your Private Key Here>")
from aleph_client.chains.ethereum import ETHAccount
account = ETHAccount("<Your Private Key Here>")
from aleph_client.chains.nuls1 import NULSAccount
account = NULSAccount("<Your Private Key Here>")
from aleph_client.chains.nuls2 import NULSAccount
account = NULSAccount("<Your Private Key Here>")
from aleph_client.chains.substrate import DOTAccount
account = DOTAccount("<Your Mnemonics Here>")
from aleph_client.chains.sol import SOLAccount
account = SOLAccount("<Your Private Key Here>")

➡️ Without a private key

Aleph-Client will try to find a "device.key" file in the current folder and use it to instantiate the account. If none is found, a new device.key file will be created with a random key.
Choose the blockchain you would like to use and import the get_fallback_account function for the relevant chain module.
# Replace "chains.ethereum" by chains.yourchain as above
from aleph_client.chains.ethereum import get_fallback_account
account = get_fallback_account()
More details on importing and creating an account are available here

2. Create a Resource

from aleph_client.chains.ethereum import ETHAccount
from aleph_client.synchronous import create_post
account = ETHAccount("<Your Private Key Here>")
response = create_post(
{'content': 'test'},
🎉 A Message object, with a POST type, has been created and is returned.
{'chain': 'NULS2',
'channel': 'MY_CHANNEL',
'sender': 'NULSd6HgaaV62iEcTZSWoaTrA3U7Jr7Vv1nXS',
'type': 'POST',
'time': 1573570575.281997,
'item_hash': '02afdbf33ff2c6ddb46349298a4598a8801cec61dbaa8f3a17ba9d1ad6dd8cb1',
'signature': 'G7yJjMCPgvX04Dd9rsz0oEuuRFa4PfuKAMOPA3Oblf6vd5YA1x15jvWLL2WycnnzYLEl0usjTiVxBl530ZOmYgw='}
All post, aggregate, and store 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.