Last updated
Edit

Freeze a Trust Line

This tutorial shows the steps to freeze an individual trust line. The issuer of a token in the XRP Ledger may freeze the trust line to a particular counterparty if that account is engaged in suspicious activity.

Tip
As a reminder, freezes only apply to issued tokens, not XRP.

Prerequisites

  • 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:
  • This tutorial assumes you have already issued a token in the XRP Ledger.
  • You cannot have enabled the No Freeze setting, which gives up your ability to freeze individual trust lines.

Example Code

Complete sample code for all of the steps of this tutorial is available under the MIT license.

Steps

1. Get Credentials

To transact on the XRP Ledger, you need an address and secret key, and some XRP. If you use the best practice of having separate "cold" and "hot" addresses, you need the keys to the cold address, which is the issuer of the token.

Caution
Ripple provides the Testnet and Devnet for testing purposes only, and sometimes resets the state of these test networks along with all balances. As a precaution, do not use the same addresses on Testnet/Devnet and Mainnet.

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:

// In browsers, use a <script> tag. In Node.js, uncomment the following line:
// const xrpl = require('xrpl')

// Wrap code in an async function so we can use await
async function main() {

  // 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)
  await client.disconnect()
}

main()

For purposes of this tutorial, use the following interface to connect and perform setup:

3. Choose Trust Line

You can only freeze one trust line per transaction, so you need to know which trust line you want. Each of your trust lines is uniquely identified by these 3 things:

  • Your own address.
  • The address of the account linked to yours via the trust line.
  • The currency code of the trust line.

There can be multiple trust lines between two accounts, each for a different currency. If you suspect a particular account is behaving maliciously, you may want to freeze all the trust lines between your accounts, one at a time. Use the account_lines method with a pair of accounts to find all trust lines between those accounts, then choose a trust line to freeze from among the results. For example:

  // Look up current trust lines -----------------------------------------------
  const issuing_address = wallet.address
  const address_to_freeze = 'rhPuJPcd9kcSRCGHWudV3tjUuTvvysi6sv'
  const currency_to_freeze = 'FOO'

  console.log('Looking up', currency_to_freeze, 'trust line from',
              issuing_address, 'to', address_to_freeze)
  const account_lines = await client.request({
    "command": "account_lines",
    "account": issuing_address,
    "peer": address_to_freeze,
    "ledger_index": "validated"
  })
  const trustlines = account_lines.result.lines
  console.log("Found lines:", trustlines)

  // Find the trust line for our currency_to_freeze ----------------------------
  let trustline = null
  for (let i = 0; i < trustlines.length; i++) {
    if(trustlines[i].currency === currency_to_freeze) {
      trustline = trustlines[i]
      break
    }
  }

  if (trustline === null) {
    console.error(`Couldn't find a ${currency_to_freeze} trustline between
                  ${issuing_address} and ${address_to_freeze}`)
    return
  }

  

For purposes of this tutorial, a second test address has created a trust line to the test address for the currency "FOO", which you can see in the following example:

4. Send TrustSet Transaction to Freeze the Trust Line

To enable or disable an Individual Freeze on a specific trust line, send a TrustSet transaction with the tfSetFreeze flag enabled. The fields of the transaction should be as follows:

FieldValueDescription
AccountStringYour issuing account's address.
TransactionTypeStringTrustSet
LimitAmountObjectObject defining the trust line to freeze.
LimitAmount.currencyStringCurrency of the trust line (cannot be XRP)
LimitAmount.issuerStringThe XRP Ledger address of the counterparty to freeze
LimitAmount.valueStringThe amount of currency you trust this counterparty to issue to you, as a quoted number. As an issuer, this is typically "0".
FlagsNumberTo enable a freeze, turn on the tfSetFreeze bit (0x00100000).

As always, to send a transaction, you prepare it by filling in all the necessary fields, sign it with your cryptographic keys, and submit it to the network. For example:

  // Send a TrustSet transaction to set an individual freeze -------------------
  // Construct a TrustSet, preserving our existing limit value
  const trust_set = {
    "TransactionType": 'TrustSet',
    "Account": issuing_address,
    "LimitAmount": {
      "value": trustline.limit,
      "currency": trustline.currency,
      "issuer": trustline.account
    },
    "Flags": xrpl.TrustSetFlags.tfSetFreeze
  }

  // Best practice for JavaScript users: use validate(tx_json) to confirm
  // that a transaction is well-formed or throw ValidationError if it isn't.
  xrpl.validate(trust_set)

  console.log('Submitting TrustSet tx:', trust_set)
  const result = await client.submitAndWait(trust_set, { wallet: wallet })
  console.log("Transaction result:", result)

  // Confirm trust line status -------------------------------------------------
  const account_lines_2 = await client.request({
    "command": "account_lines",
    "account": issuing_address,
    "peer": address_to_freeze,
    "ledger_index": "validated"
  })
  const trustlines_2 = account_lines_2.result.lines

  let line = null
  for (let i = 0; i < trustlines_2.length; i++) {
    if(trustlines_2[i].currency === currency_to_freeze) {
      line = trustlines_2[i]
      console.log(`Status of ${currency_to_freeze} line between
          ${issuing_address} and ${address_to_freeze}:
          ${JSON.stringify(line, null, 2)}`)
      if (line.freeze === true) {
        console.log(`✅ Line is frozen.`)
      } else {
        console.error(`❌ Line is NOT FROZEN.`)
      }
    }
  }
  if (line === null) {
    console.error(`Couldn't find a ${CURRENCY_TO_FREEZE} line between
        ${issuing_address} and ${address_to_freeze}.`)
  }

  

Note
If you want to freeze multiple trust lines in different currencies with the same counterparty, repeat this step for each trust line. It is possible to send several transactions in a single ledger if you use a different sequence number for each transaction.

5. 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.)

Transaction ID:(None)
Latest Validated Ledger Index:(Not connected)
Ledger Index at Time of Submission:(Not submitted)
Transaction LastLedgerSequence:(Not prepared)

6. Check Trust Line Freeze Status

At this point, the trust line from the counterparty should be frozen. You can check the freeze status of any trust line using the account_lines method with the following fields:

FieldValueDescription
accountStringYour address. (In this case, the issuing address.)
peerStringThe address of the counterparty.

Caution
The response includes all trust lines between the two accounts. (Each different currency code uses a different trust line.) Be sure to check the one for the right token.

In the response, the field "freeze": true indicates that the account from the request has enabled an Individual Freeze on that trust line. The field "freeze_peer": true indicates that the counterparty (peer) from the request has frozen the trust line. For example:

  // Confirm trust line status -------------------------------------------------
  const account_lines_2 = await client.request({
    "command": "account_lines",
    "account": issuing_address,
    "peer": address_to_freeze,
    "ledger_index": "validated"
  })
  const trustlines_2 = account_lines_2.result.lines

  let line = null
  for (let i = 0; i < trustlines_2.length; i++) {
    if(trustlines_2[i].currency === currency_to_freeze) {
      line = trustlines_2[i]
      console.log(`Status of ${currency_to_freeze} line between
          ${issuing_address} and ${address_to_freeze}:
          ${JSON.stringify(line, null, 2)}`)
      if (line.freeze === true) {
        console.log(`✅ Line is frozen.`)
      } else {
        console.error(`❌ Line is NOT FROZEN.`)
      }
    }
  }
  if (line === null) {
    console.error(`Couldn't find a ${CURRENCY_TO_FREEZE} line between
        ${issuing_address} and ${address_to_freeze}.`)
  }

  

7. (Optional) Send TrustSet Transaction to End the Freeze

If you decide that the trust line no longer needs to be frozen (for example, you investigated and decided that the suspicious activity was benign), you can end the individual freeze in almost the same way that you froze the trust line in the first place. To end an individual freeze, send a TrustSet transaction with the tfClearFreeze flag enabled. The other fields of the transaction should be the same as when you froze the trust line:

FieldValueDescription
AccountStringYour issuing account's address.
TransactionTypeStringTrustSet
LimitAmountObjectObject defining the trust line to unfreeze.
LimitAmount.currencyStringCurrency of the trust line (cannot be XRP)
LimitAmount.issuerStringThe XRP Ledger address of the counterparty to unfreeze
LimitAmount.valueStringThe amount of currency you trust this counterparty to issue to you, as a quoted number. As an issuer, this is typically "0".
FlagsNumberTo end an individual freeze, turn on the tfClearFreeze bit (0x00200000)

As always, to send a transaction, you prepare it by filling in all the necessary fields, sign it with your cryptographic keys, and submit it to the network. For example:

  // Clear the individual freeze -----------------------------------------------
  // We're reusing our TrustSet transaction from earlier with a different flag.
  trust_set.Flags = xrpl.TrustSetFlags.tfClearFreeze

  // Submit a TrustSet transaction to clear an individual freeze ---------------
  console.log('Submitting TrustSet tx:', trust_set)
  const result2 = await client.submitAndWait(trust_set, { wallet: wallet })
  console.log("Transaction result:", result2)

  console.log("Finished submitting. Now disconnecting.")
  await client.disconnect()

  

8. Wait for Validation

As before, wait for the transaction to be validated by consensus.

Transaction ID:(None)
Latest Validated Ledger Index:(Not connected)
Ledger Index at Time of Submission:(Not submitted)
Transaction LastLedgerSequence:(Not prepared)

See Also