Skip to main content

How To Connect To Subsocial

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

getSubstrateApi()#

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

FlatSubsocialApi#

Connect using FlatSubsocialApi.

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