# API Reference

This section provides a comprehensive guide on how to use the XRPL Snap API. It covers installation, interaction with the XRPL Snap, network management, and handling transactions, including exporting the private key.

***

## **Installation**

To install the XRP Ledger Snap in your MetaMask environment, use the following request:

```javascript
provider.request({
  method: 'wallet_requestSnaps',
  params: {
    ['npm:xrpl-snap']: {},
  },
});
```

**For Development**: If you are developing the XRP Ledger Snap locally, use this request to install it from your local environment:

```javascript
provider.request({
  method: 'wallet_requestSnaps',
  params: {
    ['local:http://localhost:8080']: {},
  },
});
```

{% hint style="info" %}
This is only for developer looking to contribute to the Snap
{% endhint %}

***

## **Interact with the Snap**

Once the XRP Ledger Snap is installed, you can interact with it using the following methods:

### **Making RPC Requests**

You can interact with the XRP Ledger via the Snap by sending RPC requests. Here is an example:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_request',
      params: { 
        command: 'account_info', 
        account: 'rBg...' // Add your account here
      },
    },
  },
});
```

This example requests account information from the XRP Ledger.

***

### **Network Management**

**Get Supported Networks**

To retrieve a list of networks supported by the XRPL Snap:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_getSupportedNetworks',
    },
  },
});
```

**Get Current Network**

To check the currently active network:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_getActiveNetwork',
    },
  },
});
```

**Change the Selected Network**

To switch to a different network:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_changeNetwork',
      params: { 
        chainId: 1  // Replace with the correct chainId for the desired network
      },
    },
  },
});
```

***

## **Signing and Submitting Transactions**

The XRP Ledger Snap allows you to sign and submit transactions directly from your DApp.

### **Sign and Submit a Transaction**

To sign and submit a transaction to the XRP Ledger:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_signAndSubmit',
      params: {
        TransactionType: 'Payment',
        Account: 'rBg...',     // Your account address
        Destination: 'rPT...', // Destination address
        Amount: '1000000',     // Amount in drops (1 XRP = 1,000,000 drops)
      },
    },
  },
});
```

### **Sign a Transaction Without Submitting**

If you only need to sign a transaction without submitting it to the network:

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:@peersyst/xrpl-snap',
    request: {
      method: 'npm:xrpl-snap',
      params: {
        TransactionType: 'Payment',
        Account: 'rBg...',
        Destination: 'rPT...',
        Amount: '1000000', // Amount in drops
      },
    },
  },
});
```

{% hint style="info" %}
Normally you will use the xrpl\_signAndSubmit method.
{% endhint %}

***

## **Export Private Key**

To display the user's private key in the XRP Ledger Snap use this method.&#x20;

```javascript
provider.request({
  method: 'wallet_invokeSnap',
  params: {
    snapId: 'npm:xrpl-snap',
    request: {
      method: 'xrpl_extractPrivateKey',
      params: undefined,
    },
  },
})

```

{% hint style="info" %}
The private key never leaves the MetaMask environment, therefore you as a developer can not access to it.
{% endhint %}

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://snap-docs.xrplevm.org/development/publish-your-docs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
