PHPackages                             tigusigalpa/nansen-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tigusigalpa/nansen-php

ActiveLibrary[API Development](/categories/api)

tigusigalpa/nansen-php
======================

A framework-agnostic PHP client for the Nansen AI API with first-class Laravel support.

v1.0.0(1mo ago)150MITPHPPHP ^8.1

Since Jul 15Pushed 1mo agoCompare

[ Source](https://github.com/tigusigalpa/nansen-php)[ Packagist](https://packagist.org/packages/tigusigalpa/nansen-php)[ Docs](https://github.com/tigusigalpa/nansen-php)[ RSS](/packages/tigusigalpa-nansen-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Nansen PHP
==========

[](#nansen-php)

[![Nansen AI PHP SDK](https://camo.githubusercontent.com/d32a45504ee8de5bfdcebcf2bbc8a11c19e4e8e0ecee8ee1026ec83a9c99c697/68747470733a2f2f692e706f7374696d672e63632f6e7a5070796e53362f6e616e73656e2d61692d7068702d62616e6e65722e6a7067)](https://camo.githubusercontent.com/d32a45504ee8de5bfdcebcf2bbc8a11c19e4e8e0ecee8ee1026ec83a9c99c697/68747470733a2f2f692e706f7374696d672e63632f6e7a5070796e53362f6e616e73656e2d61692d7068702d62616e6e65722e6a7067)

[![PHP Version](https://camo.githubusercontent.com/ef363a5a30025ffef1857918c40fa01e97f03929e5f87d12a14bf334a7de9220/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3838393242462e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/1de9269498b3897e6246d46854502a7878a2c26c90b04eb6d7a013e5756f8768/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74696775736967616c70612f6e616e73656e2d7068702e737667)](https://packagist.org/packages/tigusigalpa/nansen-php)

> A PHP client for the [Nansen AI API](https://docs.nansen.ai/). Works in any PHP 8.1+ project, and comes with proper Laravel 10–13 support out of the box.

I built this because talking to the Nansen API by hand gets old fast — you end up copy-pasting the same cURL boilerplate, decoding JSON, and reinventing retry logic every time. This library wraps all of that behind a fluent interface, so a request reads more or less like a sentence.

```
use Tigusigalpa\Nansen\NansenClient;

$client = NansenClient::create(['api_key' => 'YOUR_API_KEY']);

$netflows = $client
    ->smartMoney()
    ->netflows()
    ->chains(['ethereum'])
    ->limit(10)
    ->get();

foreach ($netflows->items as $entry) {
    echo $entry->chain . ' → ' . $entry->netflow . "\n";
}
```

---

What you get
------------

[](#what-you-get)

- **No framework required.** The core is plain PHP 8.1+, so you can drop it into anything.
- **Laravel, if you want it.** Auto-discovered service provider, a publishable config file, and a `Nansen` facade so you can write `Nansen::smartMoney()->netflows()`.
- **Bring your own HTTP client.** Guzzle is used by default, but anything PSR-18 works — just inject it.
- **A fluent API that actually reads well:** `->smartMoney()->netflows()->chains(['ethereum'])->limit(10)->get()`.
- **Typed responses, not loose arrays.** Everything comes back as a DTO, and lists are real collections you can `count()`, loop over, and index into.
- **You never lose data.** Each DTO keeps the untouched API response in `->raw`, so if Nansen adds a field tomorrow, you can still read it today.
- **Rate limits handled for you.** When the API returns a 429, the client backs off and retries automatically, honoring `Retry-After`. There's a clear exception hierarchy (`ApiException`, `RateLimitException`, `UnauthorizedException`, `NotFoundException`) for everything else.

---

Installation
------------

[](#installation)

```
composer require tigusigalpa/nansen-php
```

That's it for plain PHP. If you're on Laravel, read on.

### Laravel

[](#laravel)

The service provider is auto-discovered, so there's nothing to register manually. Publish the config file when you want to tweak defaults:

```
php artisan vendor:publish --provider="Tigusigalpa\Nansen\Laravel\NansenServiceProvider"
```

Then set your environment variable:

```
NANSEN_API_KEY=your_api_key_here
```

---

Configuration
-------------

[](#configuration)

Everything lives in `config/nansen.php` after publishing:

```
return [
    'api_key'     => env('NANSEN_API_KEY'),
    'base_uri'    => env('NANSEN_BASE_URI', 'https://api.nansen.ai'),
    'timeout'     => 30,
    'retries'     => 3,
    'retry_delay' => 1,
];
```

Want to use your own HTTP client (say, one with custom middleware or logging)? Bind any PSR-18 implementation in a service provider and the library will pick it up:

```
$this->app->bind(\Psr\Http\Client\ClientInterface::class, MyPsr18Client::class);
```

---

Quick Start
-----------

[](#quick-start)

### Standalone

[](#standalone)

```
