Skip to main content

Installation and Setup

npm i @stakewise/v3-sdk

If your builder doesn't support .graphql files, then you need to add a plugin. For example, for webpack this would be graphql-tag. If you are using another builder, you can easily find GQL support plugins

webpackConfig.module.rules.push(
{
test: /\.(graphql|gql)$/,
loader: 'graphql-tag/loader',
exclude: /node_modules/,
}
)

Create SDK instance

SDK without specified provider allows to call methods to get data such as sdk.vault.getVault, but doesn't allow to send transactions such as sdk.vault.deposit

import { StakeWiseSDK, Network } from '@stakewise/v3-sdk'

const sdk = new StakeWiseSDK({
network: Network.Mainnet,
endpoints: {
web3: 'https://mainnet.infura.io/v3/...',
},
})

SDK with specified provider allows to call methods to get data and send transactions

import { BrowserProvider } from 'ethers'
import { StakeWiseSDK, Network } from '@stakewise/v3-sdk'

const sdk = new StakeWiseSDK({
network: Network.Mainnet,
provider: new BrowserProvider(window.ethereum, {
name: 'mainnet',
chainId: Network.Mainnet,
}),
})

SDK with specified provider using wagmi connector. Detailed example can be found here.

import { BrowserProvider, Eip1193Provider } from 'ethers'
import { StakeWiseSDK, Network } from '@stakewise/v3-sdk'

wagmiConnector.getProvder()
.then((library) => {
const sdk = new StakeWiseSDK({
network: Network.Mainnet,
provider: new BrowserProvider(library as Eip1193Provider, {
name: 'mainnet',
chainId: Network.Mainnet,
}),
})
})

SDK Constructor Arguments:

NameTypeRequiredDescription
networkNetworkYesChain id
providerBrowserProvider or JsonRpcProviderNoYou can provide your implementation of the provender for ethers. This parameter is required to send transactions.
endpoints.web3string or Array<(string | { url: string, headers: Headers })>NoYour urls for connecting to blockchain. This parameter is required if provider is not provided. If more than one URL is provided, they will be used as fallbacks.
endpoints.subgraphstringNostakewise subgraph url
endpoints.apistringNostakewise backend url