Last updated

Enact Global Freeze

If you issue tokens in the XRP Ledger, can enact a Global Freeze to prevent users from sending your tokens to each other and trading your token in the decentralized exchange. This tutorial shows how to enact and end a Global Freeze. You might want to do this, for example, if you see signs of suspicious activity related to your issuing address in the ledger, or to off-ledger systems you use to manage your token. (For example, if your token is a stablecoin and you process withdrawals and deposits from the ledger, you may want to freeze your token while you investigate if you suspect your systems have been hacked.) You can later disable the Global Freeze setting unless you have also enabled the No Freeze setting.

Tip: As a reminder, freezes only apply to issued tokens, not XRP, and do not prevent users from sending the tokens directly back to the issuer.

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:
  • You don't need to have issued a token in the XRP Ledger to enact a Global Freeze, but the main reason you would do so is if you have already issued such a token.

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. Only the issuer's Global Freeze setting has any effect on a token.

Tip: Unlike the No Freeze setting, you can enable and disable a Global Freeze using a regular key pair or multi-signing.

For this tutorial, you can get credentials from the following interface:

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.

When you're building production-ready software, you should use an existing account, and manage your keys using a secure signing configuration.

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:

  1. JavaScript
// 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 this tutorial, click the following button to connect:

3. Send AccountSet Transaction to Start the Freeze

To enable the Global Freeze setting, send an AccountSet transaction with a SetFlag field containing the asfGlobalFreeze value (7). 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.

Caution: Enacting a global freeze affects all tokens issued by the address. Furthermore, if you use the No Freeze setting, you cannot undo this action.

For example:

  1. JavaScript
  2. WebSocket
  // Prepare an AccountSet transaction to enable global freeze -----------------
  const accountSetTx = {
    TransactionType: "AccountSet",
    Account: wallet.address,
    // Set a flag to turn on a global freeze on this account
    SetFlag: xrpl.AccountSetAsfFlags.asfGlobalFreeze
  }

  // Best practice for JS users - validate checks if a transaction is well-formed
  xrpl.validate(accountSetTx)

  // Sign and submit the AccountSet transaction to enable a global freeze ------
  console.log('Signing and submitting the transaction:', accountSetTx)
  await client.submitAndWait(accountSetTx, { wallet })
  console.log(`Finished submitting! ${wallet.address} should be frozen now.`)

  

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

5. Confirm Account Settings

After the transaction is validated, you can check your issuing account's settings to confirm that the Global Freeze flag is enabled. You can do this by calling the account_info method and checking the value of the account's Flags field to see if the lsfGlobalFreeze bit (0x00400000) is on.

  1. JavaScript
  2. WebSocket
  // Request account info for my_address to check account settings ------------
  const response = await client.request(
    {command: 'account_info', account: my_address })
  const settings = response.result
  const lsfGlobalFreeze = xrpl.LedgerEntry.AccountRootFlags.lsfGlobalFreeze

  console.log('Got settings for address', my_address);
  console.log('Global Freeze enabled?',
              ((settings.account_data.Flags & lsfGlobalFreeze) 
              === lsfGlobalFreeze))

  

Intermission: While Frozen

At this point all token issued by your address are frozen. During this time, you may want to investigate the potential security breach or take a snapshot of the balances of your token, depending on your reasons for enacting the global freeze.

Keep in mind that while a token is frozen, it is still possible for the frozen token to be sent directly to or directly from the issuer, so you may still want to disable any systems you have that are configured to send such transactions, and you may want to track incoming transactions without processing them so that you can eventually process the legitimate ones.

If you use a hot wallet or operational address, it has no special status compared to other users, so it also cannot send and receive the frozen tokens except when dealing directly with the issuer.

If you use the No Freeze setting then the Global Freeze continues forever. If you want to resume issuing tokens, you must create a new account and start over from there.

Otherwise, you can continue to the next step whenever you're ready.

6. Send AccountSet Transaction to End the Freeze

To end the Global Freeze, send an AccountSet transaction with a ClearFlag field containing the asfGlobalFreeze value (7). As always, you first prepare the transaction, sign it, and finally submit it to the network.

For example:

  1. JavaScript
  2. WebSocket
  // Now we disable the global freeze ------------------------------------------
  const accountSetTx2 = {
    TransactionType: "AccountSet",
    Account: wallet.address,
    // ClearFlag let's us turn off a global freeze on this account
    ClearFlag: xrpl.AccountSetAsfFlags.asfGlobalFreeze
  }

  // Best practice for JS users - validate checks if a transaction is well-formed
  xrpl.validate(accountSetTx2)

  // Sign and submit the AccountSet transaction to end a global freeze ---------
  console.log('Signing and submitting the transaction:', accountSetTx2)
  const result = await client.submitAndWait(accountSetTx2, { wallet: wallet })
  console.log("Finished submitting!")

  

7. Wait for Validation

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

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

8. Confirm Account Settings

After the transaction is validated, you can confirm the status of the Global Freeze flag in the same way as before: by calling the account_info method and checking the value of the account's Flags field to see if the lsfGlobalFreeze bit (0x00400000) is off.

See Also