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

# testConnection()

## Overview

Tests whether the configured provider credentials are valid. For Pinata, this calls the authentication test endpoint and returns `true` when Pinata returns a success message.

## Purpose

Use `testConnection()` to validate stored or newly entered provider credentials before performing write or read operations.

## Endpoint / Method

```ts
async testConnection(): Promise<boolean>
```

Provider endpoint:

```http
GET https://api.pinata.cloud/data/testAuthentication
```

## Parameters

This method does not accept parameters.

### Request schema table

No request body or method parameters.

## Response

Returns a `Promise<boolean>`.

| Value            | Description                                |
| ---------------- | ------------------------------------------ |
| `true`           | Authentication succeeded.                  |
| Rejected promise | Authentication or provider request failed. |

### Response schema table

| Type      | Description                                                                                           |
| --------- | ----------------------------------------------------------------------------------------------------- |
| `boolean` | `true` when Pinata authentication succeeds. Failed HTTP responses throw instead of returning `false`. |

## Examples

### Example request

```ts
const meshkit = await Meshkit.init({
  provider: "pinata",
  providerToken: "PINATA_JWT",
});

const connected = await meshkit.testConnection();
```

### Example response

```ts
true
```

## Errors

| Error                                | Cause                           |
| ------------------------------------ | ------------------------------- |
| `HTTP error 401` or provider details | Invalid or expired Pinata JWT.  |
| `HTTP error 403` or provider details | Token lacks required access.    |
| Network error                        | Runtime could not reach Pinata. |

### Error schema table

| Field     | Type     | Description                                                           |
| --------- | -------- | --------------------------------------------------------------------- |
| `name`    | `string` | Standard JavaScript error name.                                       |
| `message` | `string` | Pinata error details when available, otherwise `HTTP error {status}`. |

## Notes

* A `false` value is not returned for failed HTTP responses. Failed provider responses throw.
* Use this method when saving or rotating credentials.

## Best Practices

* Run this method before the first write operation in onboarding flows.
* Avoid calling it before every SDK operation; it is a network request.

## Related APIs

* [init()](/meshkit-documentation/api/init.md)
* [store()](/meshkit-documentation/api/store.md)
* [Authentication](/meshkit-documentation/authentication.md)


---

# 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://bittu-1.gitbook.io/meshkit-documentation/api/testconnection.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.
