Getting Started
Installation
Using a package manager
Use your favourite package manager to install:
- npm
- Yarn
- pnpm
npm install --save @builddao/near-social-js
yarn add @builddao/near-social-js
pnpm add @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:
- JavaScript (via package manager)
- JavaScript (via CDN)
- TypeScript
const { Social } = require('@builddao/near-social-js');
const social = new Social();
var social = new NEARSocialSDK();
import { Social } from '@builddao/near-social-js';
const social = new Social();
By default, the Social SDK is initialized for the mainnet social contract (social.near
) and the mainnet RPC provider (https://rpc.mainnet.near.org).
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:
- JavaScript (via package manager)
- JavaScript (via CDN)
- TypeScript
const { Social } = require('@builddao/near-social-js');
const social = new Social({
contractId: 'mysocialcontract.near',
});
var social = new NEARSocialSDK({
contractId: 'mysocialcontract.near',
});
import { Social } from '@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.
- JavaScript (via package manager)
- JavaScript (via CDN)
- TypeScript
const { Social } = require('@builddao/near-social-js');
const social = new Social({
contractId: 'v1.social08.testnet',
network: 'testnet',
});
var social = new NEARSocialSDK({
contractId: 'v1.social08.testnet',
network: 'testnet'
});
import { NetworkIDEnum, Social } from '@builddao/near-social-js';
const social = new Social({
contractId: 'v1.social08.testnet',
network: NetworkIDEnum.Testnet,
});
If using the network ID, make sure you provide the correct social contract for that network.
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:
- JavaScript (via package manager)
- JavaScript (via CDN)
- TypeScript
const { Social } = require('@builddao/near-social-js');
const social = new Social({
network: {
apiKey: 'some key',
url: 'https://custom-rpc.near.org',
},
});
var social = new NEARSocialSDK({
network: {
apiKey: 'some key',
url: 'https://custom-rpc.near.org'
}
});
import { Social } from '@builddao/near-social-js';
const social = new Social({
network: {
apiKey: 'some key',
url: 'https://custom-rpc.near.org',
},
});