> For the complete documentation index, see [llms.txt](https://docs.rabet.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rabet.io/api/api-refrence.md).

# API refrence

## Methods

### rabet.connect()

To interact with the user's account in Rabet, you must first connect to it.&#x20;

For connecting to the user account, you must send a connection request to the user. If the user confirms, you will receive the user account public key; otherwise, you will receive a rejected error.

```typescript
interface ConnectResult {
    publicKey: string;
    error?: string;
}

rabet.connect(): Promise<ConnectResult>;
```

```javascript
rabet.connect()
    .then(result => console.log(`User active public key is: ${result.publicKey}`))
    .catch(error => console.error(`Error: ${error}`));
```

### rabet.sign()

To send an XDR to the connected account and let users sign it, you need to use this method.

```javascript
interface SignResult {
    xdr: string;
    error: string;
}

rabet.sign(): Promise<SignResult>;
```

```javascript
const network = StellarSdk.Networks.PUBLIC;
const XDR = 'AAAAA...;

rabet.sign(XDR, network)
    .then(result => {
        console.log(`I have the signed XDR here: ${result.xdr}`);
    })
    .catch(error => console.error(error));
```

### rabet.disconnect()

This method removes the connection between the extension and the client. In order to interact with the extension, you need to call `rabet.connect()` again.

```typescript
rabet.disconnect(): Promise<void>
```

### rabet.isUnlocked()

This method returns a `Promise` that resolves to a `boolean` indicating if Rabet is unlocked by the user. Rabet must be unlocked in order to perform any operation involving user accounts. Note that this method does not indicate if the user has exposed any accounts to the caller.

```typescript
rabet.isUnlocked(): Promise<Boolean>
```

### rabet.close()

When calling `rabet.connect()` or `rabet.sign()` a new window shows up that lasts for 30 seconds, but use this method if you want to close that window manually.

```typescript
rabet.close(): Promise<void>
```

## Events

### accountChanged

This event triggers whenever the user changes the active account in the extension wallet.

```typescript
rabet.on('accountChanged', handler: () => void);
```

### networkChanged

This event triggers whenever the user changes the network in the extension wallet.

```typescript
rabet.on('networkChanged', handler: (networkId: string) => void);
```
