import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import TOCInline from '@theme/TOCInline';

# Getting Started

<TOCInline
  maxHeadingLevel={4}
  toc={toc}
/>

## Installation

### Using a package manager

Use your favourite package manager to install:

```bash npm2yarn
npm install --save @builddao/near-social-js
```

### Download via a CDN

Include the minified browser bundle directly in your HTML like so:

```html
<html>
  ...
  <script src="https://github.com/NEARBuilders/near-social-js/releases/latest/download/near-social-js.min.js"></script>
  ...
</html>
```


## Initialization

To initialize the SDK, simply instantiate the [`Social`](../api-reference/social) class:

<Tabs
  defaultValue="javascript-via-package-manager"
  values={[
    { label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
    { label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
    { label: 'TypeScript', value: 'typescript' },
  ]}>
  <TabItem value="javascript-via-package-manager">

    ```js
    const { Social } = require('@builddao/near-social-js');

    const social = new Social();
    ```

  </TabItem>
  <TabItem value="javascript-via-cdn">

    ```js
    var social = new NEARSocialSDK();
    ```

  </TabItem>
  <TabItem value="typescript">

    ```typescript
    import { Social } from '@builddao/near-social-js';

    const social = new Social();
    ```

  </TabItem>
</Tabs>

:::note

By default, the Social SDK is initialized for the mainnet social contract ([`social.near`](https://nearblocks.io/address/social.near)) and the mainnet RPC provider (https://rpc.mainnet.near.org).

:::

:::note

See [`INewSocialOptions`](../api-reference/types#inewsocialoptions) for more information on what options are supported.

:::

## Initialization with a different contract

You can initialize the SDK with a different social contract account by specifying it in the options:

<Tabs
  defaultValue="javascript-via-package-manager"
  values={[
    { label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
    { label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
    { label: 'TypeScript', value: 'typescript' },
  ]}>
  <TabItem value="javascript-via-package-manager">

    ```js
    const { Social } = require('@builddao/near-social-js');

    const social = new Social({
      contractId: 'mysocialcontract.near',
    });
    ```

  </TabItem>
  <TabItem value="javascript-via-cdn">

    ```js
    var social = new NEARSocialSDK({
      contractId: 'mysocialcontract.near',
    });
    ```

  </TabItem>
  <TabItem value="typescript">

    ```typescript
    import { Social } from '@builddao/near-social-js';

    const social = new Social({
      contractId: 'mysocialcontract.near',
    });
    ```

  </TabItem>
</Tabs>

## Initialization with a different network ID

You can use a specific network by initializing the SDK with a known network ID. See [networks](../api-reference/networks) on the supported networks and the RPC URLs they point to.

<Tabs
  defaultValue="javascript-via-package-manager"
  values={[
    { label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
    { label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
    { label: 'TypeScript', value: 'typescript' },
  ]}>
  <TabItem value="javascript-via-package-manager">

    ```js
    const { Social } = require('@builddao/near-social-js');

    const social = new Social({
      contractId: 'v1.social08.testnet',
      network: 'testnet',
    });
    ```

  </TabItem>
  <TabItem value="javascript-via-cdn">

    ```js
    var social = new NEARSocialSDK({
      contractId: 'v1.social08.testnet',
      network: 'testnet'
    });
    ```

  </TabItem>
  <TabItem value="typescript">

    ```typescript
    import { NetworkIDEnum, Social } from '@builddao/near-social-js';

    const social = new Social({
      contractId: 'v1.social08.testnet',
      network: NetworkIDEnum.Testnet,
    });
    ```

  </TabItem>
</Tabs>

:::caution

If using the network ID, make sure you provide the correct social contract for that network.

:::

:::note

An [`UnknownNetworkError`](../api-reference/errors#unkownnetworkerror) will be thrown if the supplied network ID is not known.

:::

## Initialization with a custom RPC provider

If you want to use your own RPC provider, you can initialize the SDK by specifying it in the options:

<Tabs
  defaultValue="javascript-via-package-manager"
  values={[
    { label: 'JavaScript (via package manager)', value: 'javascript-via-package-manager' },
    { label: 'JavaScript (via CDN)', value: 'javascript-via-cdn' },
    { label: 'TypeScript', value: 'typescript' },
  ]}>
  <TabItem value="javascript-via-package-manager">

    ```js
    const { Social } = require('@builddao/near-social-js');

    const social = new Social({
      network: {
        apiKey: 'some key',
        url: 'https://custom-rpc.near.org',
      },
    });
    ```

  </TabItem>
  <TabItem value="javascript-via-cdn">

    ```js
    var social = new NEARSocialSDK({
      network: {
        apiKey: 'some key',
        url: 'https://custom-rpc.near.org'
      }
    });
    ```

  </TabItem>
  <TabItem value="typescript">

    ```typescript
    import { Social } from '@builddao/near-social-js';

    const social = new Social({
      network: {
        apiKey: 'some key',
        url: 'https://custom-rpc.near.org',
      },
    });
    ```

  </TabItem>
</Tabs>
