# Connect to the Network

Interacting with VeChainThor requires only an instance of `ThorClient` that is configured for the relevant network. Once the connection is established, this instance can be utilized to interact in an asynchronous manner. Below is a snippet that demonstrates importing the library and initializing a client:

```js
import { ThorClient } from "@vechain/sdk-network";
const thor = ThorClient.at("https://mainnet.vechain.org");
```

The snippet connects to the MainNet, where all production related activity is found.

Additionally there is a TestNet available for testing and development purposes. This allows developers to experiment without risking real assets.

To connect to the TestNet use `https://testnet.vechain.org` as URL. If you have deployed a [thor solo node](/how-to-run-a-node/how-to-run-a-thor-solo-node.md), it is normally available on `http://localhost:8669`.

{% hint style="info" %}
The `ThorClient` uses a `HttpClient` underneath to communicate with the VeChain nodes with a [JSON API](https://mainnet.vechain.org/doc/swagger-ui/).

The default [`HttpClient` implementation is using Fetch](https://github.com/vechain/vechain-sdk-js/blob/v1.0.0/packages/network/src/utils/http/http-client.ts) and can be replaced with any custom implementation as long as the interfaces are met.
{% endhint %}

To test the connectivity we'll get request the first and last block from the chain and output their number & id:

```js
// get the current latest & best block from the chain
const bestBlock = await thor.blocks.getBestBlockCompressed();
console.log("Best Block:", bestBlock.number, bestBlock.id);

// get the first and genesis block from the chain
const genesisBlock = await thor.blocks.getBlockCompressed(0);
console.log("Genesis Block:", genesisBlock.number, genesisBlock.id);
```

You can test the above snippet here:

{% embed url="<https://stackblitz.com/github/vechain-energy/example-snippets/tree/v1.0.0/sdk/connect?ctl=1&embed=1&file=index.mjs&hideExplorer=1&hideNavigation=1&view=editor>" %}

{% hint style="info" %}
The `ThorClient` provides a multitude of properties with access to all relevant functionality on VeChain. You can find examples and details about all of them in the [Thor Client docs](/developer-resources/sdks-and-providers/sdk/thor-client.md).
{% endhint %}


---

# 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.vechain.org/developer-resources/how-to-build-on-vechain/connect-to-the-network.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.
