# XRP

Source: https://developers.bitgo.com/docs/xrp

## XRP

XRP is the native asset on the XRP Ledger blockchain. XRP can be accessed with the following coin types:

| Environment    | Coin Type | Faucet |
| :------------- | :-------- | :----- |
| XRP Altnet     | txrp      |        |
| XRP Production | xrp       |        |
| XRP Testnet    | txrp      | https://xrpl.org/resources/dev-tools/xrp-faucets/ |

### Explorer
<a href="https://livenet.xrpl.org/" target="_blank" rel="noreferrer">https://livenet.xrpl.org/</a>


### Generating wallets

```javascript
bitgo
  .coin('txrp')
  .wallets()
  .generateWallet({
    label: 'My Test Wallet',
    passphrase: 'secretpassphrase1a5df8380e0e30',
  })
  .then(function (wallet) {
    // print the new wallet
    console.dir(wallet);
  });
```
```shell
LABEL="My Test Wallet"
PASSPHRASE="secretpassphrase1a5df8380e0e30"

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d "{ \"label\": \"$LABEL\", \"passphrase\": \"$PASSPHRASE\" }" \
http://$BITGO_EXPRESS_HOST/api/v2/txrp/wallet/generate
```

Before you can use an XRP wallet, it must be initialized on the XRP blockchain (or XRP Ledger). When you create an XRP
wallet, BitGo sends 4 initialization transactions on the XRP network to generate the wallet.

Until BitGo confirms the initialization transaction, the wallet is _not_ ready for use, and the API does _not_
expose the receive address. This is to protect users from losing assets by sending to a wallet that does not exist on the
network.

> 🚧 **Warning:** Do not use an XRP wallet while BitGo initializes it or you may lose assets.

The fee for creating an XRP wallet is currently approximately 1.2 XRP. In production, there is a limit of 5 wallets total per enterprise.

> 📘 **Note:** To inquire about increasing your limit, contact BitGo at support@bitgo.com.

### Creating addresses

```javascript
bitgo
  .coin('txrp')
  .wallets()
  .getWallet({ id: '585c51a5df8380e0e3082e46' })
  .then(function (wallet) {
    return wallet.createAddress();
  })
  .then(function (newAddress) {
    // print new address details
    console.dir(newAddress);
  });
```
```shell
WALLET=585c51a5df8380e0e3082e46

curl -X POST \
-H "Authorization: Bearer $ACCESS_TOKEN" \
https://app.bitgo-test.com/api/v2/txrp/wallet/$WALLET/address
```

A key difference between XRP and Bitcoin is that XRP has no concept of UTXOs, and operates on an account-based model
instead. Additionally, XRP transactions only support one input and one output. That means that the `sendMany` call is
not supported.

The BIP-32 standard therefore cannot be taken advantage of, and hence generated XRP addresses differ only in their
sequentially incrementing destination tag components.

Destination tags indicate beneficiaries or destinations for payments. You can make transactions without a destination tag. However, a destination tag is required when sending to a BitGo wallet.

### Balances

XRP (XRP) is the native asset of the XRP ledger. The base unit of XRP is drop:

- 1 drop is (<code>10<sup>-6</sup></code>) or 0.000001 XRP.
- 1 XRP is (<code>10<sup>6</sup></code>) or 1000000 drops (1 million).

BitGo supports balances in string format: `balanceString`, `confirmedBalanceString`, and `spendableBalanceString`.

### Tokens

XRP supports tokens transactions. This means you can now make transactions with other tokens apart from native XRP coin.

#### Enable token

To make token transactions you first need to enable the token in your wallet address(es). Once enabled, you can receive and send that respective token. This process takes some fees from your account (`0.000045 xrp` is the minimum and most common fee for enabling tokens).
```javascript
bitgo
  .coin('txrp')
  .wallets()
  .get({ id: walletId })
  .then(function (wallet) {
    return wallet.sendMany({
      type: 'enabletoken',
      recipients: [
        {
          amount: '0',
          address: yourWalletAddress,
          tokenName: 'txrp:tokenID',
        },
      ],
      walletPassphrase: yourWalletPassphrase,
    })
  });
```

> 📘 **Note:** closeRemainderTo is the address you want to send all remaining token balance when turning it off.

#### XRPL Authorized Trustlines

A user can hold an XRPL token on an XRP address only if the user initiates a trustline with the issuer of that token. Enabling the token achieves this.

**Trustlines:** Trustlines on the XRP Ledger (XRPL) are bilateral ledger entries that enable the holding and transfer of issued assets (IOUs) between accounts. Unlike XRP, which can be freely held without any restrictions, these trustlines define a credit relationship where each party sets a limit to how much of a particular asset they are willing to hold.

There are two types of trustlines that can allow user to hold a xrpl token.

1. **Regular Trustlines:** A regular trustline allows a user to hold a token issued by an issuer. For example, if User A wants to hold Token X issued by Issuer I, User A must initiate a trustline transaction to establish the connection.

2. **Authorized Trustlines:** Authorized trustlines can be established in two ways, but the order of operations does not impact the outcome. The trustline only becomes active once both the user and issuer complete their respective transactions.

🔹 **User-Initiated Authorization:** The user first initiates a trustline transaction (similar to a regular trustline). The issuer then sends an authorization transaction to complete the trustline.

🔹 **Issuer-Initiated Authorization:** The issuer first sends an authorization trustline transaction to the user. The user then completes the trustline by sending their own trustline transaction.

**Requirement for Authorized Trustlines:** The issuer determines the requirement for trustline authorization. If the issuer account has the `asfRequireAuth` flag enabled, any trustline to that issuer must be explicitly authorized by the issuer.

#### Send tokens

Just as for your native token you would be able to send tokens (from token enabled addresses) to other wallets. Here is an example of it:

```javascript
bitgo
  .coin('txrp:tokenID')
  .wallets()
  .get({ id: walletId })
  .then(function (wallet) {
    return wallet.sendMany({
        type: 'payment',
        recipients: [
          {
            amount,
            address: receiverAddress,
          },
        ],
        walletPassphrase: yourWalletPassphrase,
      });
  });
```

> 📘 **Note:** While the XRP token standard supports up to 81 decimal places on-chain, BitGo currently supports a maximum of 15 decimal places.

### Transactions

The BitGo XRP multisig contract currently only supports one sender and one recipient so the `sendMany` is not supported.
