Skip to main content

Getting Started

Installation

Using a package manager

Use your favourite package manager to install:

npm install --save @builddao/near-social-js

Download via a CDN

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

<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 class:

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

const social = new Social();
note

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

note

See 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:

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

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

Initialization with a different network ID

You can use a specific network by initializing the SDK with a known network ID. See networks on the supported networks and the RPC URLs they point to.

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

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

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

note

An UnknownNetworkError 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:

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

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