# Interaction with the XRP Ledger

This section will guide you through interacting with the XRP Ledger using the XRP Ledger Snap. You'll learn how to request account balances, submit transactions, make payments, create trustlines, and send tokens.

Before using the XRP Ledger Snap you must read first the official documentation of the XRPL.

{% embed url="<https://xrpl.org/>" %}

***

## Getting account information

### **Getting Account Balance**

To retrieve the balance of an XRP Ledger account, you can use the following method:

<pre class="language-javascript"><code class="lang-javascript"><strong>const res = await provider.request({
</strong>  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_request',
      params: {
        command: 'account_info',
        account: 'rYourXRPAccountHere',
      },
    },
  },
})
console.log(res.account_data.Balance);
console.log(res.account_data.OwnerCount);

</code></pre>

{% hint style="info" %}
In the XRP Ledger you need 10 XRP to active your account.&#x20;
{% endhint %}

{% hint style="info" %}
The Balance will be returned in drops
{% endhint %}

### Getting the available balance

The balance you get from the response is not the available balance that the account has to spend.&#x20;

Each account has  a reserve:&#x20;

* Base reserve: **10 XRP**
* Owner reserve: **2 XRP** per item

So to get the available balance in drops:

$$
available = Max(0, Balance - 10*10^6-2*10^6\*OwnerCount)
$$

To learn more visit:

{% embed url="<https://xrpl.org/docs/concepts/accounts/reserves>" %}

### Converting drops to XRP

A drop is the minimum amount valid in the XRP Ledger, each drop is equal to 0.000001 XRP.

You can easily convert drops to xrp with `xrpl.js`.

{% embed url="<https://xrpl.org/docs/references/protocol/data-types/currency-formats#xrp-amounts>" %}

***

## **Submitting Transactions**

### **Making a Payment**

To send XRP from one account to another, you can submit a payment transaction:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'Payment',
        Account: 'rYourXRPAccountHere', // The Snap's XRP account
        Destination: 'rRecipientXRPAccountHere',
        Amount: '1000000', // 1 XRP in drops
      },
    },
  },
})
```

This transaction sends 1 XRP from your account to the specified destination account.

### **Creating a Trustline**

A trustline is required to hold tokens issued by other accounts on the XRP Ledger. Here’s how to create a trustline:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'TrustSet',
        Account: 'rYourXRPAccountHere',
        LimitAmount: {
          currency: 'TOKEN', // Add the currency of the Token fe. USD
          issuer: 'rIssuerAccountHere',
          value: '1000', // Maximum amount of the token you can hold
        },
      },
    },
  },
})
```

This transaction establishes a trustline allowing your account to hold up to 1000 units of a specified token issued by another account.

### **Sending a Token**

Once a trustline is established, you can send tokens to another account as follows:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'Payment',
        Account: 'rYourXRPAccountHere',
        Destination: 'rRecipientXRPAccountHere',
        Amount: {
          currency: 'TOKEN',
          value: '10', // Number of tokens to send
          issuer: 'rIssuerAccountHere',
        },
      },
    },
  },
})
```

This transaction sends 10 units of the specified token from your account to the recipient's account.

To learn more about the tokens in the XRP Ledger visit:

{% embed url="<https://xrpl.org/docs/concepts/tokens>" %}

***

## More examples

If you need more examples about all the transactions that you can submit and how to do it visit:

{% embed url="<https://github.com/XRPLF/xrpl-dev-portal/tree/master/_code-samples>" %}
