> For the complete documentation index, see [llms.txt](https://help.tokenpocket.pro/developer-en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.tokenpocket.pro/developer-en/extension-wallet/api-reference/xrp-provider-api.md).

# XRP Provider API

TokenPocket Extension injects an XRP Provider into the page. Developers can use it to connect the current address and initiate XRP transfers.

## Provider Injection

The following object is available on the page:

```ts
window.tokenpocket.xrp
```

{% hint style="info" %}
The current XRP interface is lightweight and mainly focused on address connection and native XRP transfers.
{% endhint %}

## Quick Start

### Get Current Address

```ts
const wallet = await window.tokenpocket.xrp.connect();
console.log(wallet.address);
```

### Send XRP

```ts
const res = await window.tokenpocket.xrp.sendXrp({
  from: 'r...',
  to: 'r...',
  amount: '1',
  destinationTag: '10001',
});

console.log(res.txid);
```

## API List

### connect

Requests connection for the current site and returns the active XRP address.

```ts
connect(): Promise<{
  address: string;
}>
```

Notes:

* Returns the currently selected XRP address.
* Throws an error if the user rejects authorization.

Example:

```ts
const { address } = await window.tokenpocket.xrp.connect();
console.log(address);
```

### sendXrp

Sends a native XRP transfer.

```ts
sendXrp(tx: {
  from: string;
  to: string;
  amount: string | number;
  destinationTag?: string | number;
}): Promise<{
  txid: string;
}>
```

Parameters:

* `from`: Sender address
* `to`: Receiver address
* `amount`: Transfer amount
* `destinationTag`: Optional destination tag

Returns:

* `txid`: Transaction hash

Example:

```ts
const result = await window.tokenpocket.xrp.sendXrp({
  from: 'rSenderAddress',
  to: 'rReceiverAddress',
  amount: '1',
  destinationTag: '10001',
});

console.log(result.txid);
```

### sendToken

Token transfers are not supported in the current version.

```ts
sendToken(tx: object): Promise<never>
```

Notes:

* The current implementation always returns `Not supported!`.

## Error Handling

Use `try/catch` for all Provider calls.

```ts
try {
  const wallet = await window.tokenpocket.xrp.connect();
  console.log(wallet.address);
} catch (error) {
  console.error(error);
}
```

Common failure cases:

* User rejects the connection request.
* User rejects transfer confirmation.
* Invalid parameter format.
* No XRP address is available in the current wallet.

## Compatibility Notes

* Only `window.tokenpocket.xrp` is injected.
* The current version mainly supports address connection and `sendXrp`.
* `sendToken` is not available yet.
