Modifying mosaic supply

Alter the supply of a mosaic.

Prerequisites

Method #01: Using the SDK

In this example, we are going to increase a supply mutable mosaic in 1,000,000 units.

1. Define a MosaicSupplyChangeTransaction as in the next code snippet. Then, replace the mosaicId and divisibility with the targetted mosaic properties.

// replace with network type
const networkType = NetworkType.TEST_NET;
// replace with private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = Account.createFromPrivateKey(privateKey, networkType);
// replace with mosaic id
const mosaicIdHex = '7cdf3b117a3c40cc';
const mosaicId = new MosaicId(mosaicIdHex);
// replace with mosaic divisibility
const divisibility = 0;
// replace with mosaic units to increase
const delta = 1000000;

const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create(
    Deadline.create(),
    mosaicId,
    MosaicSupplyChangeAction.Increase,
    UInt64.fromUint(delta * Math.pow(10, divisibility)),
    networkType,
    UInt64.fromUint(2000000));
// replace with network type
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
// replace with private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = symbol_sdk_1.Account.createFromPrivateKey(privateKey, networkType);
// replace with mosaic id
const mosaicIdHex = '7cdf3b117a3c40cc';
const mosaicId = new symbol_sdk_1.MosaicId(mosaicIdHex);
// replace with mosaic divisibility
const divisibility = 0;
// replace with mosaic units to increase
const delta = 1000000;
const mosaicSupplyChangeTransaction = symbol_sdk_1.MosaicSupplyChangeTransaction.create(symbol_sdk_1.Deadline.create(), mosaicId, symbol_sdk_1.MosaicSupplyChangeAction.Increase, symbol_sdk_1.UInt64.fromUint(delta * Math.pow(10, divisibility)), networkType, symbol_sdk_1.UInt64.fromUint(2000000));
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
                "http://api-01.us-west-1.symboldev.network:3000/")) {
            final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
            // replace with private key
            final String privateKey = "1111111111111111111111111111111111111111111111111111111111111111";
            final Account account = Account
                    .createFromPrivateKey(privateKey, networkType);
            // replace with mosaic id
            final String mosaicIdHex = "7cdf3b117a3c40cc";
            final MosaicId mosaicId = new MosaicId(mosaicIdHex);
            // replace with mosaic divisibility
            final int divisibility = 0;
            // replace with mosaic units to increase
            final int delta = 1000000;

            final MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransactionFactory
                    .create(
                            networkType,
                            mosaicId,
                            MosaicSupplyChangeActionType.INCREASE,
                            BigDecimal.valueOf(delta * Math.pow(10, divisibility)).toBigInteger())
                    .maxFee(BigInteger.valueOf(2000000)).build();

Note

Symbol works with absolute amounts. To get an absolute amount, multiply the number of assets you want to increase/decrease by 10divisibility. For example, if the mosaic has divisibility 2, to increase 10 units (relative) you should define 1000 (absolute) instead.

  1. Sign the transaction with the mosaic creator account and announce it to the network.
// replace with meta.generationHash (nodeUrl + '/block/1')
const networkGenerationHash = '44D2225B8932C9A96DCB13508CBCDFFA9A9663BFBA2354FEEC8FCFCB7E19846C';
const signedTransaction = account.sign(mosaicSupplyChangeTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'http://api-01.us-west-1.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();

transactionHttp
    .announce(signedTransaction)
    .subscribe((x) => console.log(x), (err) => console.error(err));
// replace with meta.generationHash (nodeUrl + '/block/1')
const networkGenerationHash = '44D2225B8932C9A96DCB13508CBCDFFA9A9663BFBA2354FEEC8FCFCB7E19846C';
const signedTransaction = account.sign(mosaicSupplyChangeTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'http://api-2-01.us-west-1.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
transactionHttp
    .announce(signedTransaction)
    .subscribe((x) => console.log(x), (err) => console.error(err));
            final String generationHash = repositoryFactory.getGenerationHash().toFuture().get();

            final SignedTransaction signedTransaction = account
                    .sign(mosaicSupplyChangeTransaction, generationHash);


            final TransactionRepository transactionRepository = repositoryFactory
                    .createTransactionRepository();
            transactionRepository.announce(signedTransaction).toFuture().get();
        }

Otherwise, you can decrease a mosaic supply by changing MosaicSupplyChangeAction.Increase to MosaicSupplyChangeAction.Decrease. In this second case, the mosaic creator account must own at least delta units to decrease the mosaic supply.

Method #02: Using the CLI

symbol-cli transaction mosaicsupplychange --action Increase --mosaic-id 7cdf3b117a3c40cc --delta 1000000