# 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);
```


---

# 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://docs.rabet.io/api/api-refrence.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.
