モザイクとメッセージを2つのアカウント間で送信

定義して、署名したら転送トランザクションをアナウンスします。

This guide will show you how to send 10 symbol.xym from your account to Bob’s, whose address is TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ.

前提条件

  • 入門セクション を完了している
  • 新しい アカウント を作成します。
  • アカウントに手数料を支払うために十分な symbol.xym を入金してください。

方法 #01: デスクトップウォレットを使用する

  1. デスクトップウォレットのホームから 転送 タブをクリックします。
../../_images/desktop-transfer-1.gif

2. Fill out the necessary information for the transfer transaction. For this example, you need to specify that you are sending 10 XYM to Bob (TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ). You can add a message, but it is not necessary in this case.

../../_images/desktop-transfer-2.gif

3. Once you have filled out all the information, click 「Send」. A popup will show. Read and verify the information, then enter your wallet password and click 「Confirm」.

4. You can verify that the transaction was successful by going back to the 「Dashboard」 tab. At first, it might show up under 「Unconfirmed」 transactions as the transaction becomes included in a block, but you should soon be able to see it under the 「Confirmed」 transactions.

方法 #02: SDK を使用する

  1. 新しいターミナルで、送信者のアカウントに関するトランザクションを監視して、ネットワークによって承認または拒否されたかを確認します。
symbol-cli monitor all --address <YOUR-ADDRESS>

2. Open a new file and define the TransferTransaction. Include Bob’s address as the recipient, and attach 10 symbol.xym.

Symbol では、モザイクの単位を 絶対量 で定義します。絶対量を取得するには、送りたいアセット量に 10divisibility を乗じてください。例えば、モザイクが 可分性 2 である場合、10 単位 (相対量) を送信するには 1000 (絶対量) と定義します。

// replace with recipient address
const rawAddress = 'TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ';
const recipientAddress = Address.createFromRawAddress(rawAddress);
// replace with network type
const networkType = NetworkType.TEST_NET;
// replace with symbol.xym id
const networkCurrencyMosaicId = new MosaicId('5E62990DCAC5BE8A');
// replace with network currency divisibility
const networkCurrencyDivisibility = 6;

const transferTransaction = TransferTransaction.create(
    Deadline.create(),
    recipientAddress,
    [new Mosaic (networkCurrencyMosaicId,
        UInt64.fromUint(10 * Math.pow(10, networkCurrencyDivisibility)))],
    PlainMessage.create('This is a test message'),
    networkType,
    UInt64.fromUint(2000000));
// replace with recipient address
const rawAddress = 'TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ';
const recipientAddress = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
// replace with network type
const networkType = symbol_sdk_1.NetworkType.TEST_NET;
// replace with symbol.xym id
const networkCurrencyMosaicId = new symbol_sdk_1.MosaicId('5E62990DCAC5BE8A');
// replace with network currency divisibility
const networkCurrencyDivisibility = 6;
const transferTransaction = symbol_sdk_1.TransferTransaction.create(symbol_sdk_1.Deadline.create(), recipientAddress, [new symbol_sdk_1.Mosaic(networkCurrencyMosaicId, symbol_sdk_1.UInt64.fromUint(10 * Math.pow(10, networkCurrencyDivisibility)))], symbol_sdk_1.PlainMessage.create('This is a test message'), networkType, symbol_sdk_1.UInt64.fromUint(2000000));
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
                "http://api-01.us-east-1.096x.symboldev.network:3000")) {
            // replace with recipient address
            final String rawAddress = "TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ";
            final UnresolvedAddress recipientAddress = Address.createFromRawAddress(rawAddress);
            final NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
            // replace with symbol.xym id
            final MosaicId networkCurrencyMosaicId = new MosaicId("5E62990DCAC5BE8A");
            // replace with network currency divisibility
            final Integer networkCurrencyDivisibility = 6;
            // replace with relative amount of symbol.xym to send
            final BigInteger amount = BigInteger.valueOf(10);

            final Mosaic mosaic = new Mosaic(networkCurrencyMosaicId,
                    amount.multiply(BigInteger.valueOf(10).pow(networkCurrencyDivisibility)));
            final TransferTransaction transferTransaction = TransferTransactionFactory
                    .create(
                            networkType,
                            recipientAddress,
                            Collections.singletonList(mosaic),
                            PlainMessage.create("This is a test message"))
                    .maxFee(BigInteger.valueOf(2000000)).build();

すでにお気づきだと思いますが、転送トランザクションではモザイクの配列をパラメータとして必要とします。これは一度で複数のモザイクを添付したトランスファートランザクションを送ることができます。

複数のモザイクを所有している場合は、同じトランザクションでそれらを一緒に送信できます:

    [new Mosaic( new MosaicId('7CDF3B117A3C40CC'), UInt64.fromUint(1000)),
        new Mosaic ( new MosaicId('5E62990DCAC5BE8A'), UInt64.fromUint(10 * Math.pow(10, 6)))],
[new symbol_sdk_1.Mosaic(new symbol_sdk_1.MosaicId('7CDF3B117A3C40CC'), symbol_sdk_1.UInt64.fromUint(1000)),
    new symbol_sdk_1.Mosaic(new symbol_sdk_1.MosaicId('5E62990DCAC5BE8A'), symbol_sdk_1.UInt64.fromUint(10 * Math.pow(10, 6)))], 
                            Arrays.asList(new Mosaic(new MosaicId("7CDF3B117A3C40CC"),
                                            BigInteger.valueOf(1000)),
                                    new Mosaic(new MosaicId("5E62990DCAC5BE8A"),
                                            BigInteger.valueOf(10000000))),

3. Sign the transaction with your account. Then, include the network generation hash seed to make the transaction only valid for your network. To retrieve the network generration hash seed, open nodeUrl + '/node/info' in a new browser tab and copy meta.networkGenerationHashSeed value.

// replace with sender private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = Account.createFromPrivateKey(privateKey, networkType);
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash = '1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const signedTransaction = account.sign(transferTransaction, networkGenerationHash);
console.log('Payload:', signedTransaction.payload);
console.log('Transaction Hash:', signedTransaction.hash);
// replace with sender private key
const privateKey = '1111111111111111111111111111111111111111111111111111111111111111';
const account = symbol_sdk_1.Account.createFromPrivateKey(privateKey, networkType);
// replace with meta.networkGenerationHash (nodeUrl + '/node/info')
const networkGenerationHash = '1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const signedTransaction = account.sign(transferTransaction, networkGenerationHash);
console.log('Payload:', signedTransaction.payload);
console.log('Transaction Hash:', signedTransaction.hash);
            // replace with private key
            final String privateKey = "1111111111111111111111111111111111111111111111111111111111111111";
            // replace with network generation hash
            final String generationHash = repositoryFactory.getGenerationHash().toFuture().get();

            final Account account = Account
                    .createFromPrivateKey(privateKey, networkType);
            final SignedTransaction signedTransaction = account
                    .sign(transferTransaction, generationHash);
  1. 署名したら トランザクションをネットワークへアナウンス できます。
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.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 node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.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 TransactionRepository transactionRepository = repositoryFactory
                    .createTransactionRepository();
            transactionRepository.announce(signedTransaction).toFuture().get();
        }

5. Open the terminal where you are monitoring the transaction’s status. The transaction should appear as confirmed after ±15 seconds and the amount defined gets transferred from the sender’s account to the recipient’s account. If the terminal raises an error, you can check the error code description here.

方法 #03: CLI を使用する

Open a terminal window and run the following command to transfer 10 XYM from your default account.

Remember to replace TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ with the recipient address you want to send mosaics too and @symbol.xym::10000000 with the desired absolute amount.

Optionally, you can set a custom message with the option --message.

 symbol-cli transaction transfer --recipient-address TB6Q5E-YACWBP-CXKGIL-I6XWCH-DRFLTB-KUK34I-YJQ --mosaics "@symbol.xym::10000000" --message "This is a test message" --sync