Skip to content

Mosaic definition transaction

Chun Lam edited this page Feb 21, 2024 · 4 revisions
import { Deadline, Account, NetworkType, UInt64, MosaicDefinitionTransaction, 
    MosaicNonce, MosaicId, MosaicProperties 
} from 'tsjs-xpx-chain-sdk';
import { Network } from '../utils';

const network = new Network('http://localhost:3000');

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

const nonce = MosaicNonce.createRandom();
const mosaicId = MosaicId.createFromNonce(nonce, sender.publicAccount);
const mosaicDefinitionTx = MosaicDefinitionTransaction.create(
    Deadline.create(),
    nonce,
    mosaicId,
    MosaicProperties.create({
        "supplyMutable": false,
        "transferable": true,
        "divisibility": 3,
        "duration": UInt64.fromUint(100000),
    }),
    NetworkType.MIJIN_TEST
);

network.networkProperties.then(networkProperties => {
    const signedMosaicDefinitionTransaction = sender.preV2Sign(mosaicDefinitionTx, networkProperties.generationHash);

    network.announceAndWaitForConfirmation(signedMosaicDefinitionTransaction).then(tx => {
        console.log('Confirmed:');
        console.log(tx);
    });
});