# Require Destination Tags

The Require Destination Tag setting is designed for addresses that host balances for multiple people or purposes, to prevent people from sending money and forgetting to use a [destination tag](/ja/docs/concepts/transactions/source-and-destination-tags) to identify whom to credit. When this setting is enabled on your address, the XRP Ledger rejects [any payment](/ja/docs/concepts/payment-types) to your address if it does not specify a destination tag.

This tutorial demonstrates how to enable the Require Destination Tag flag on your account.

The meanings of specific destination tags are entirely up to the logic built on top of the XRP Ledger. The ledger has no way of knowing whether any specific tag is valid in your system, so you must still be ready to receive transactions with the wrong destination tag. Typically, this involves providing a customer support experience that can track down payments made incorrectly and credit customers accordingly, and possibly also bouncing unwanted payments.

## Prerequisites

- You need a funded XRP Ledger account, with an address, secret key, and some XRP. For production, you can use the same address and secret consistently. For this tutorial, you can generate new test credentials as needed.
- You need a connection to the XRP Ledger network. As shown in this tutorial, you can use public servers for testing.
- You should be familiar with the Getting Started instructions for your preferred client library. This page provides examples for the following:
  - **JavaScript** with the [xrpl.js library](https://github.com/XRPLF/xrpl.js/). See [Get Started Using JavaScript](/ja/docs/tutorials/get-started/get-started-javascript) for setup steps.
  - **Python** with the [`xrpl-py` library](https://xrpl-py.readthedocs.io/). See [Get Started using Python](/ja/docs/tutorials/get-started/get-started-python) for setup steps.
  - You can also read along and use the interactive steps in your browser without any setup.


script
script
## Example Code

Complete sample code for all the steps of these tutorials is available under the [MIT license](https://github.com/XRPLF/xrpl-dev-portal/blob/master/LICENSE).

- See [Code Samples: Require Destination Tags](https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples/require-destination-tags/) in the source repository for this website.


## Steps

### 1. Get Credentials

To transact on the XRP Ledger, you need an address and secret key, and some XRP. For development purposes, you can get these using the following interface:

Testnetの暗号鍵を作成する

div
Rippleは[TestnetとDevnet](/ja/docs/concepts/networks-and-servers/parallel-networks)をテストの目的でのみ運用しており、その状態とすべての残高を定期的にリセットしています。予防措置として、Testnet、DevnetとMainnetで同じアドレスを使用**しない**ことをお勧めします。

When you're building production-ready software, you should use an existing account, and manage your keys using a [secure signing configuration](/ja/docs/concepts/transactions/secure-signing).

### 2. Connect to the Network

You must be connected to the network to submit transactions to it. The following code shows how to connect to a public XRP Ledger Testnet server a supported [client library](/ja/docs/references/client-libraries):

JavaScript

```js
// You can also use a <script> tag in browsers or require('xrpl') in Node.js
import xrpl from 'xrpl'

// Define the network client
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233")
await client.connect()

// ... custom code goes here

// Disconnect when done (If you omit this, Node.js won't end the process)
client.disconnect()
```

Python

```py
import asyncio
from xrpl.asyncio.clients import AsyncWebsocketClient


async def main():
    # Define the network client
    async with AsyncWebsocketClient("wss://s.altnet.rippletest.net:51233") as client:
        # inside the context the client is open

        # ... custom code goes here

    # after exiting the context, the client is closed


asyncio.run(main())
```

For this tutorial, click the following button to connect:

Testnetに接続する

div
strong
接続ステータス：
span
接続されていません
### 3. Send AccountSet Transaction

To enable the `RequireDest` flag, set the [`asfRequireDest` value (`1`)](/ja/docs/references/protocol/transactions/types/accountset#accountset-flags) in the `SetFlag` field of an [AccountSet transaction](/docs/references/protocol/transactions/types/accountset). To send the transaction, you first *prepare* it to fill out all the necessary fields, then *sign* it with your account's secret key, and finally *submit* it to the network.

For example:

JavaScript

```js
  // Send AccountSet transaction -----------------------------------------------
  const prepared = await client.autofill({
    "TransactionType": "AccountSet",
    "Account": wallet.address,
    "SetFlag": xrpl.AccountSetAsfFlags.asfRequireDest
  })
  console.log("Prepared transaction:", prepared)

  const signed = wallet.sign(prepared)
  console.log("Transaction hash:", signed.hash)

  const submit_result = await client.submitAndWait(signed.tx_blob)
  console.log("Submit result:", submit_result)
```

Python

```py
        # Send AccountSet transaction -----------------------------------------------
        tx = AccountSet(
            account=wallet.address,
            set_flag=AccountSetAsfFlag.ASF_REQUIRE_DEST,
        )

        # Sign and autofill the transaction (ready to submit)
        signed_tx = await autofill_and_sign(tx, client, wallet)
        print("Transaction hash:", signed_tx.get_hash())

        # Submit the transaction and wait for response (validated or rejected)
        print("Submitting transaction...")
        submit_result = await submit_and_wait(signed_tx, client)
        print("Submit result:", submit_result)
```

Send AccountSet
Send AccountSet

div
### 4. Wait for Validation

Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For information on how to set an expiration for transactions, see [Reliable Transaction Submission](/ja/docs/concepts/transactions/reliable-transaction-submission).)

table
tr
th
トランザクションのID:
td
(無）
tr
th
最新の検証レジャーインデックス：
td
接続されていません
tr
th
送信時のレジャーインデックス：
td
（まだ送信されません）
tr
th
トランザクションの
code
LastLedgerSequence
:
td
(準備されません）
tr
### 5. Confirm Account Settings

After the transaction is validated, you can check your account's settings to confirm that the Require Destination Tag flag is enabled.

JavaScript

```js
  // Confirm Account Settings --------------------------------------------------
  let account_info = await client.request({
    "command": "account_info",
    "account": address,
    "ledger_index": "validated"
  })
  const flags = xrpl.parseAccountFlags(account_info.result.account_data.Flags)
  console.log(JSON.stringify(flags, null, 2))
  if (flags.lsfRequireDestTag) {
    console.log("Require Destination Tag is enabled.")
  } else {
    console.log("Require Destination Tag is DISABLED.")
  }
```

Python

```py
        # Confirm Account Settings --------------------------------------------------
        print("Requesting account information...")
        account_info = await client.request(
            AccountInfo(
                account=wallet.address,
                ledger_index="validated",
            )
        )

        # Verify that the AccountRoot lsfRequireDestTag flag is set
        flags = account_info.result["account_data"]["Flags"]
        if flags & 0x00020000 != 0:
            print(f"Require Destination Tag for account {wallet.address} is enabled.")
        else:
            print(f"Require Destination Tag for account {wallet.address} is DISABLED.")
```

Confirm Settings
Confirm Settings

div
For further confirmation, you can send test transactions (from a different address) to confirm that the setting is working as you expect it to. If you a payment with a destination tag, it should succeed, and if you send one *without* a destination tag, it should fail with the error code [`tecDST_TAG_NEEDED`](/ja/docs/references/protocol/transactions/transaction-results/tec-codes).

Test Payments
Send XRP (with Destination Tag)
Send XRP (without Destination Tag)

div
## See Also

- **Concepts:**
  - [Accounts](/ja/docs/concepts/accounts)
  - [Source and Destination Tags](/ja/docs/concepts/transactions/source-and-destination-tags)
  - [Transaction Cost](/ja/docs/concepts/transactions/transaction-cost)
  - [Payment Types](/ja/docs/concepts/payment-types)
- **References:**
  - [account_info method](/docs/references/http-websocket-apis/public-api-methods/account-methods/account_info)
  - [AccountSet transaction](/docs/references/protocol/transactions/types/accountset)
  - [AccountRoot Flags](/ja/docs/references/protocol/ledger-data/ledger-entry-types/accountroot#accountroot-flags)