Skip to main content

How To Connect To Subsocial

You can connect to subsocial using @subsocial/api libraries.


getSubstrateApi() is a polkadot.js ApiPromise that provides a connection to a blockchain RPC node, retrieves data from the chain and executes transactions on the chain.

import { getSubstrateApi } from '@subsocial/api'
const api = getSubstrateApi({ endpoint: substrateUrl })

Learn more in the documentation


Connect using FlatSubsocialApi.

import { newFlatSubsocialApi } from '@subsocial/api'
const initSubsocialApi = async () => {
const api = await newFlatSubsocialApi({
substrateNodeUrl, // Substrate node URL e.g.
offchainUrl, // Offchain URL e.g.
ipfsNodeUrl // IPFS node URL e.g.
return api
// connect to subsocial
const flatApi = initSubsocialApi()