モザイクを使用した資産のトークン化
左側のメニューから "モザイク" タブをクリックします。
ページの上部から "新しいモザイクの作成" タブをクリックします。
3. Determine the properties of the mosaic you desire to create. You can read "Mosaic Properties" to decide how do you want to configure your mosaic. Click "Send".
ポップアップの情報を確認し、ウォレットのパスワードを入力します。 "確認" をクリックします。これでトランザクションがネットワークに送信されます。
トランザクションが確認されたら "所有モザイク" タブに戻り、モザイクが作成されたことを確認できます。
1. Open a new file and define a MosaicDefinitionTransaction. This transaction defines the mosaic properties your mosaic will have. You can read Mosaic Properties to decide how do you want to configure your mosaic.
// replace with network type
const networkType = NetworkType.TEST_NET;
// replace with private key
const privateKey =
'1111111111111111111111111111111111111111111111111111111111111111';
const account = Account.createFromPrivateKey(privateKey, networkType);
// replace with duration (in blocks)
const duration = UInt64.fromUint(0);
// replace with custom mosaic flags
const isSupplyMutable = true;
const isTransferable = true;
const isRestrictable = true;
// replace with custom divisibility
const divisibility = 0;
const nonce = MosaicNonce.createRandom();
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(epochAdjustment),
nonce,
MosaicId.createFromNonce(nonce, account.address),
MosaicFlags.create(isSupplyMutable, isTransferable, isRestrictable),
divisibility,
duration,
networkType,
);
// 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 duration (in blocks)
const duration = symbol_sdk_1.UInt64.fromUint(0);
// replace with custom mosaic flags
const isSupplyMutable = true;
const isTransferable = true;
const isRestrictable = true;
// replace with custom divisibility
const divisibility = 0;
const nonce = symbol_sdk_1.MosaicNonce.createRandom();
const mosaicDefinitionTransaction = symbol_sdk_1.MosaicDefinitionTransaction.create(symbol_sdk_1.Deadline.create(epochAdjustment), nonce, symbol_sdk_1.MosaicId.createFromNonce(nonce, account.address), symbol_sdk_1.MosaicFlags.create(isSupplyMutable, isTransferable, isRestrictable), divisibility, duration, networkType);
// replace with node endpoint
try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
"NODE_URL")) {
final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
// replace with private key
final String privateKey = "1111111111111111111111111111111111111111111111111111111111111111";
final Account account = Account
.createFromPrivateKey(privateKey, networkType);
// replace with duration (in blocks)
final BlockDuration duration = new BlockDuration(10);
// replace with custom mosaic flags
final boolean isSupplyMutable = true;
final boolean isTransferable = true;
final boolean isRestrictable = true;
// replace with custom divisibility
final int divisibility = 0;
final MosaicNonce nonce = MosaicNonce.createRandom();
final MosaicDefinitionTransaction mosaicDefinitionTransaction = MosaicDefinitionTransactionFactory
.create(networkType,
nonce,
MosaicId.createFromNonce(nonce, account.getPublicAccount()),
MosaicFlags.create(isSupplyMutable, isTransferable, isRestrictable),
divisibility,
duration)
.build();
2. Define a MosaicSupplyChangeTransaction to set the initial supply. For instance, we can set it to 1,000,000 mosaic units.
// replace with mosaic units to increase
const delta = 1000000;
const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create(
Deadline.create(epochAdjustment),
mosaicDefinitionTransaction.mosaicId,
MosaicSupplyChangeAction.Increase,
UInt64.fromUint(delta * Math.pow(10, divisibility)),
networkType,
);
// replace with mosaic units to increase
const delta = 1000000;
const mosaicSupplyChangeTransaction = symbol_sdk_1.MosaicSupplyChangeTransaction.create(symbol_sdk_1.Deadline.create(epochAdjustment), mosaicDefinitionTransaction.mosaicId, symbol_sdk_1.MosaicSupplyChangeAction.Increase, symbol_sdk_1.UInt64.fromUint(delta * Math.pow(10, divisibility)), networkType);
// replace with mosaic units to increase
final int delta = 1000000;
final MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransactionFactory
.create(
networkType,
mosaicDefinitionTransaction.getMosaicId(),
MosaicSupplyChangeActionType.INCREASE,
BigDecimal.valueOf(delta * Math.pow(10, divisibility)).toBigInteger())
.build();
注釈
Symbol は 絶対量 を扱います。絶対量を取得するには、作成したいアセットの量に 10divisibility を乗じてください。例えば、モザイクが 可分性 2 である場合、10 単位 (相対) 作成するには 1000 (絶対) と定義します。
3. Announce both transactions together using an アグリゲートトランザクション.
Include the network generation hash to make the transaction only valid for your network.
Open NODE_URL /node/info
in a new browser tab and copy the meta.networkGenerationHash
value.
const aggregateTransaction = AggregateTransaction.createComplete(
Deadline.create(epochAdjustment),
[
mosaicDefinitionTransaction.toAggregate(account.publicAccount),
mosaicSupplyChangeTransaction.toAggregate(account.publicAccount),
],
networkType,
[],
UInt64.fromUint(2000000),
);
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash =
'1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const signedTransaction = account.sign(
aggregateTransaction,
networkGenerationHash,
);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const transactionHttp = repositoryFactory.createTransactionRepository();
transactionHttp.announce(signedTransaction).subscribe(
(x) => console.log(x),
(err) => console.error(err),
);
const aggregateTransaction = symbol_sdk_1.AggregateTransaction.createComplete(symbol_sdk_1.Deadline.create(epochAdjustment), [
mosaicDefinitionTransaction.toAggregate(account.publicAccount),
mosaicSupplyChangeTransaction.toAggregate(account.publicAccount),
], networkType, [], symbol_sdk_1.UInt64.fromUint(2000000));
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash = '1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const signedTransaction = account.sign(aggregateTransaction, networkGenerationHash);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
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 AggregateTransaction aggregateTransaction = AggregateTransactionFactory
.createComplete(
networkType,
Arrays.asList(
mosaicDefinitionTransaction.toAggregate(account.getPublicAccount()),
mosaicSupplyChangeTransaction.toAggregate(account.getPublicAccount())
))
.maxFee(BigInteger.valueOf(2000000)).build();
final String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
final SignedTransaction signedTransaction = account
.sign(aggregateTransaction, generationHash);
final TransactionRepository transactionRepository = repositoryFactory
.createTransactionRepository();
transactionRepository.announce(signedTransaction).toFuture().get();
}
トランザクションが承認されたら、他のアカウントへ作ったモザイクの 1 単位を 転送 してみたり、 モザイクプロパティの変更 または ネームスペースをモザイクへリンク してみましょう。
ターミナルを開き、次のコマンドを実行します。
symbol-cli transaction mosaic