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

# PHP SDK

This guide is designed to help you seamlessly integrate and interact with the SendingNetwork API using PHP. This documentation will walk you through the steps to set up, authenticate, and utilize the features of SendingNetwork to enable efficient and secure network communication within your PHP applications.

## Installation

```php
composer require sending-network/sdn-php-sdk
```

## Usage

You will need a developer key to access the Edge Network. For further insight into the mechanism and to request a developer key, please consult the provided guide [here](/sending.network/sdk-documentation/developer-key.md).

### Prepare a configuration file

In the file *bot.creds.json*, make sure to include the node URL, wallet address, private key, and developer key.

```json
{
    "nodeUrl": "https://portal0101.sending.network",
    "walletAddress": "<WALLET_ADDRESS>",
    "privateKey": "<PRIVATE_KEY>",
    "developerKey": "<DEVELOPER_KEY>"
}
```

### Create an instance of `SDNClient`

```php
require('vendor/autoload.php');
use SdnSdk\SDNClient;

$json_data = file_get_contents("bot.creds.json");
$config = json_decode($json_data,true);
$client = new SDNClient($config['nodeUrl']);

// login
$token = $client->login($config['walletAddress'], $config['privateKey'], $config['developerKey']);

// add listener for events
$client->addListener(function ($event) {
    // process room event here
    print_r($event);
}, "m.room.message");

// start listen
$client->listenForever();
```

### Call API functions

```php
// create new room
$client->createRoom("room name");

// invite user
$client->getRoom($roomId)->inviteUser($userId);

// send message
$client->getRoom($roomId)->sendText("hello");
```

## Examples

See more use cases in `examples` directory.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://sending-network.gitbook.io/sending.network/sdk-documentation/php-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
