Sirius Chain Developer Center 0.2.6

Sirius Chain Developer Center 0.2.6

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

›Mosaic

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 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

Monitoring

  • Monitor transaction

Mosaic

  • Creating a mosaic
  • Getting the mosaic information
  • Getting the asset identifier behind a namespace with receipts
  • 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

Creating a mosaic

Follow this guide to create a mosaic.

Background

Mosaics can be used to represent any asset in the blockchain such as objects, tickets, coupons, stock share representation, and even your cryptocurrency.

Prerequisites

  • Finish registering a namespace guide
  • have an account with xpx
  • XPX-Chain-SDK or XPX-Chain-CLI
  • A text editor or IDE
  • An account with XPX and at least one namespace

Getting into some code

Define two transactions to create a mosaic:

  1. A mosaic definition transaction, to create the mosaic, with the following properties:
PropertyValueDescription
Divisibility0The mosaic won’t be divisible. Determines up to what decimal place the mosaic can be divided.
Duration1000The mosaic will be created for the next 1000 blocks. If you want to create a non-expiring mosaic, do not set this property.
Supply mutabletrueThe mosaic supply can change at a later point.
TransferabletrueThe mosaic can be transferred between arbitrary accounts. Otherwise, the mosaic can be only transferred back to the mosaic creator.
Golang
JavaScript
nonce := rand.New(rand.NewSource(time.Now().UTC().UnixNano())).Uint32()

mosaicDefinitionTrx, err := client.NewMosaicDefinitionTransaction(
sdk.NewDeadline(time.Hour),
nonce,
account.PublicAccount.PublicKey,
sdk.NewMosaicProperties(true, true, 0, sdk.Duration(1000)),
)
if err != nil {
panic(err)
}
    const nodeURL = "http://localhost:3000";

const transactionHttp = new TransactionHttp(nodeURL);

var mosaicDuration = (1 * 365 * 24 * 60 * 4 ); // 1 year - 15 sec per block

const privateKey = process.env.PRIVATE_KEY;
const account = Account.createFromPrivateKey(privateKey, NetworkType.TEST_NET);

const nonce = MosaicNonce.createRandom();
var mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);

const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
mosaicId,
MosaicProperties.create({
supplyMutable: true,
transferable: true,
divisibility: 0,
duration: UInt64.fromUint(mosaicDuration),
}),
NetworkType.TEST_NET
)
  1. A mosaic supply change transaction, to set the supply. We are going to create 1.000.000 mosaic units.
Golang
JavaScript
mosaic, err := sdk.NewMosaicIdFromNonceAndOwner(nonce, account.PublicAccount.PublicKey)
if err != nil {
panic(err)
}

mosaicSupplyChangeTrx, err := client.NewMosaicSupplyChangeTransaction(
sdk.NewDeadline(time.Hour),
mosaic,
sdk.Increase,
sdk.Amount(1000000),
)
if err != nil {
panic(err)
}
const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create(
Deadline.create(),
mosaicId,
MosaicSupplyType.Increase,
UInt64.fromUint(1000000),
NetworkType.TEST_NET
);

Note:

Sirius Chain mainly works with absolute amounts. To get an absolute amount, multiply the amount of assets you want to create by 10divisibility. For example, if the mosaic has divisibility 2, to create 10 units (relative) you should define 1000 (absolute) instead.

  1. Both transactions can be announced together using an aggregate transaction.
Golang
JavaScript
// Convert an aggregate transaction to an inner transaction including transaction signer.
mosaicDefinitionTrx.ToAggregate(account.PublicAccount)
mosaicSupplyChangeTrx.ToAggregate(account.PublicAccount)

// Create an aggregate complete transaction
aggregateTransaction, err := client.NewCompleteAggregateTransaction(
// The maximum amount of time to include the transaction in the blockchain.
sdk.NewDeadline(time.Hour),
// Inner transactions
[]sdk.Transaction{mosaicDefinitionTrx, mosaicSupplyChangeTrx,},
)
const aggregateTransaction = AggregateTransaction.createComplete(
Deadline.create(),
[
mosaicDefinitionTransaction.toAggregate(account.publicAccount),
mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)
],
NetworkType.TEST_NET,
[]);

What’s next?

Transfer one mosaic created to another account or modify its properties following the next guide.

← Monitor transactionGetting the mosaic information →
  • Background
  • Prerequisites
  • Getting into some code
  • What’s next?
  • Join #general discussion
  • Ask development questions
  • Follow the dev updates
  • Explore Github
Protocol
BlockConsensus AlgorithmsCryptographyInflationNodeReceiptTransactionValidating
Built-in Features
AccountAccount FilterAggregate TransactionCross-Chain SwapsExchange MarketMetadataMosaicMultisig AccountNamespaceSuper contractTransfer Transaction
References
REST APISDKsXPX-Chain-CLICheat Sheet
Documentation Forked From NEM
Copyright © 2020 ProximaX