Developer Center

Developer Center

  • Getting Started
  • Built-in Features
  • REST API Endpoints
  • Guides
  • Cheat Sheet

›Transfer Transaction

Getting Started

  • What is Sirius Chain
  • Setting up your workstation
  • Writing your first application

Built-in Features

  • Account
  • Mosaic (SDA)
  • Namespace
  • Transfer Transaction
  • Aggregate Transaction
  • Multisig Account
  • Metadata
  • Account Restriction
  • Cross-Chain Swaps
  • Exchange Market
  • Decentralized Exchange Market
  • Liquidity Provider
  • Storage

Protocol

  • Node
  • Block
  • Cryptography
  • Transaction
  • Validating
  • Consensus Algorithms
  • Receipt
  • Inflation

REST API

  • Overview
  • Tools
  • Serialization
  • Websockets
  • Status Errors

SDKs

  • Overview
  • Architecture
  • Languages
  • Extending Sirius Chain Capabilities
  • SDK Development
  • SDK Documentation

Wallets & Explorers

  • Wallets & Explorers

Cheat Sheet

  • Sirius Chain Cheat Sheet

Guides

  • Overview
  • External Guides
  • Account

    • Creating and opening an account
    • Getting account information
    • Getting the amount of XPX sent to an account
    • Reading transactions from an account

    Account Restriction

    • Preventing spam attacks with account restrictions

    Aggregate Transaction

    • Sending payouts with aggregate-complete transaction
    • Creating an escrow with aggregate bonded transaction
    • Asking for mosaics with aggregate-bonded transaction
    • Signing announced aggregate-bonded transactions

    Block

    • Listening to New Blocks
    • Getting block by height

    Cross Chain Swaps

    • Atomic cross-chain swap between Sirius public and private chains

    Metadata

    • Account Metadata
    • Mosaic Metadata
    • Namespace Metadata
    • Account Metadata (Deprecated since 0.7.0 Sirius Chain release)
    • Mosaic Metadata (Deprecated since 0.7.0 Sirius Chain release)
    • Namespace Metadata (Deprecated since 0.7.0 Sirius Chain release)

    Monitoring

    • Monitor transaction

    Mosaic

    • Creating a mosaic (SDA)
    • Getting the mosaic information
    • Getting the asset identifier behind a namespace with receipts

    Mosaic Levy

    • Modifying Mosaic Supply

    Multisig Account

    • Converting an account to multisig
    • Modifying a multisig account
    • Creating a multi-level multisig-account
    • Sending a multisig transaction

    Namespace

    • Registering a namespace
    • Registering a subnamespace
    • Getting the Namespace information
    • Linking a namespace to a mosaic
    • Linking namespace to account

    Transfer Transaction

    • Transfer transaction
    • Sending an encrypted message

    Storage

    • Data Modification Cancel
    • Data Modification
    • Download Channel
    • Download Payment
    • Drive Closure
    • Finish Download Channel
    • Prepare Bc Drive
    • Replicator Offboarding
    • Replicator Onboarding
    • Storage Payment
    • Verification Payment

Storage

  • Overview
  • Participate
  • External Economy
  • Roles
  • Verification
  • Challenge
  • Rewards
  • Transaction Schemas
  • Built-In Features

    • Drive
    • Replicator
    • Verifier
    • Supercontracts

    Protocols

    • Cross-Block Protocol
    • Fair Streaming

    Storage User Application

    • Overview
    • Getting Started
    • Managing Drives
    • Managing Drive Files
    • Downloading Data

Sending an encrypted message

Send an encrypted message that only can be read by the recipient account.

Prerequisites

  • Finish the getting started section.
  • Finish the sending a transfer transaction guide.
  • XPX-Chain-SDK or XPX-Chain-CLI.
  • A text editor or IDE.
  • An account with XPX.

Background

Imagine that Alice wants to timestamp a sensitive message to send to an account representing her academic certificate.

Alice knows that sending a transfer transaction with a plain message through the public network will make the content of the message publicly available.

Thus, Alice sends an encrypted message that is only readable by herself and those with access to the academic certificate.

Getting into some code

  1. Create an account for Alice, and another for the certificate using xpx2-cli.
xpx2-cli account generate --save

Introduce network type (MIJIN_TEST, MIJIN, MAIN_NET, TEST_NET): TEST_NET
Do you want to save it? [y/n]: y
Introduce Sirius Chain Node URL. (Example: http://bctestnet1.brimstone.xpxsirius.io:3000): http://bctestnet1.brimstone.xpxsirius.io:3000
Insert profile name (blank means default and it could overwrite the previous profile): alice
xpx2-cli account generate --save

Introduce network type (MIJIN_TEST, MIJIN, MAIN_NET, TEST_NET): TEST_NET
Do you want to save it? [y/n]: y
Introduce Sirius Chain Node URL. (Example: http://bctestnet1.brimstone.xpxsirius.io:3000): http://bctestnet1.brimstone.xpxsirius.io:3000
Insert profile name (blank means default and it could overwrite the previous profile): certificate
  1. Create an encrypted message for the certificate, signing it with Alice’s account.
Golang
TypeScript
conf, err := sdk.NewConfig(context.Background(), []string{"http://bctestnet1.brimstone.xpxsirius.io:3000"})
if err != nil {
panic(err)
}

// Use the default http client
client := sdk.NewClient(nil, conf)

aliceAccount, err := client.NewAccountFromPrivateKey(os.Getenv("ALICE_PRIVATE_KEY"))
if err != nil {
panic(err)
}

certificateAccount, err := client.NewAccountFromPublicKey(os.Getenv("CERTIFICATE_PUBLIC_KEY"))
if err != nil {
panic(err)
}

encryptedMessage, err := aliceAccount.EncryptMessage("This message is secret", certificateAccount)
if err != nil {
panic(err)
}

const privateKey = '<privateKey>';
const aliceAccount = Account.createFromPrivateKey(privateKey, NetworkType.TEST_NET);

const certificateAccountPublicKey = '<publicKey>';
const certificatePublicAccount = PublicAccount.createFromPublicKey(certificateAccountPublicKey, NetworkType.TEST_NET);

const networkGenerationHash = process.env.NETWORK_GENERATION_HASH as string;

  1. Attach the encrypted message to a transfer transaction, setting the certificate address as the recipient.
Golang
TypeScript
transferTransaction, err := client.NewTransferTransaction(
sdk.NewDeadline(time.Hour),
certificateAccount.Address,
[]*sdk.Mosaic{sdk.XpxRelative(10)},
encryptedMessage,
)
if err != nil {
panic(err)
}

const transferTransaction = TransferTransaction.create(
Deadline.create(),
certificatePublicAccount.address,
[],
aliceAccount.encryptMessage('This message is secret', certificatePublicAccount),
NetworkType.TEST_NET);

  1. Sign the transaction with Alice’s account.
Golang
TypeScript
signedTransaction, err := aliceAccount.Sign(transferTransaction)
if err != nil {
panic(err)
}
const signedTransaction = aliceAccount.sign(transferTransaction, networkGenerationHash);
  1. Once signed, announce the transaction to the network.
Golang
TypeScript
transactionHash, err := client.Transaction.Announce(context.Background(), signedTransaction)
if err != nil {
panic(err)
}
const transactionHttp = new TransactionHttp('http://bctestnet1.brimstone.xpxsirius.io:3000');

var transactionHash = signedTransaction.hash;

transactionHttp
.announce(signedTransaction)
.subscribe(x => console.log(x), err => console.error(err));
  1. After the transaction gets confirmed, fetch it using the transaction hash output from (5). You can now decrypt the message using either the certificate account or address account.
Golang
TypeScript
transactionInfo, err := client.Transaction.GetTransaction(context.Background(), transactionHash)
if err != nil {
panic(err)
}

const certificatePrivateKey = '<privateKey>';
const certificateAccount = Account.createFromPrivateKey(certificatePrivateKey, NetworkType.TEST_NET);

const alicePublicKey = '<publicKey>';
const alicePublicAccount = PublicAccount.createFromPublicKey(alicePublicKey, NetworkType.TEST_NET);

transactionHttp.getTransaction(transactionHash)
.subscribe((transaction) => {
var plainMessage = certificateAccount.decryptMessage(new EncryptedMessage(transaction.message), alicePublicAccount);
});

If you managed to read the message, try to decrypt it using another unrelated account to ensure that only the defined participants can read the encrypted content.

← Transfer transactionData Modification Cancel →
  • Prerequisites
  • Background
  • Getting into some code
  • Follow our profile
  • Ask development questions
  • Join our Discord channel
  • Explore our Youtube channel
  • Explore Github
Protocol
BlockConsensus AlgorithmsCryptographyInflationNodeReceiptTransactionValidating
Built-in Features
AccountAggregate TransactionCross-Chain SwapsExchange MarketDecentralized Exchange MarketMetadataMosaicMultisig AccountNamespaceTransfer TransactionStorageLiquidity Provider
References
REST APISDKsCheat Sheet
Includes Documentation Forked from NEM
Copyright © 2025 Sirius Chain