Skip to content

Mosaic supply change transaction

Yaaccount edited this page Jun 14, 2019 · 4 revisions
import { Deadline, Account, NetworkType, TransactionHttp, Listener, UInt64, SignedTransaction, PublicAccount, MosaicId, MosaicSupplyChangeTransaction, MosaicSupplyType } from 'tsjs-xpx-chain-sdk';

const transactionHttp = new TransactionHttp('http://localhost:3000');
const listener = new Listener('http://localhost:3000');

const sender = Account.createFromPrivateKey(
    '28FCECEA252231D2C86E1BCF7DD541552BDBBEFBB09324758B3AC199B4AA7B78',
    NetworkType.MIJIN_TEST);

const announceAndWaitForConfirmation = (signedTx: SignedTransaction) => {
    listener.open().then(() => {
        const subscription = listener.confirmed(PublicAccount.createFromPublicKey(signedTx.signer, NetworkType.MIJIN_TEST).address).subscribe(confirmed => {
            if (confirmed && confirmed.transactionInfo && confirmed.transactionInfo.hash === signedTx.hash) {
                console.log('confirmed: ' + JSON.stringify(confirmed));
                subscription.unsubscribe();
                listener.close();
            }
        }, error => {
            console.error(error);
        }, () => {
            console.log('done.');
        });

        transactionHttp.announce(signedTx);
    });
}

const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create(
    Deadline.create(),
    new MosaicId([1584382191,1337794379]),
    MosaicSupplyType.Increase,
    UInt64.fromUint(1000),
    NetworkType.MIJIN_TEST
)

const signedMosaicSupplyChangeTransaction = sender.sign(mosaicSupplyChangeTransaction);

const mosaicSupplyChangeTransactionExample = () => {
    announceAndWaitForConfirmation(signedMosaicSupplyChangeTransaction);
}

export {
    mosaicSupplyChangeTransactionExample
}