Skip to content

Commit

Permalink
[rpc urls] removed default rpc urls
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-diamond committed Sep 4, 2024
1 parent 32a8282 commit f3edc81
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,23 @@ Create SDK instance
```typescript
import { StakeWiseSDK, Network } from '@stakewise/v3-sdk'

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

```
#### SDK Constructor Arguments:

| Name | Type | Required | Description |
|--------------------|--------------------------------------|----------|----------------|
| network | `Network` | **Yes** | Chain id |
| provider | `BrowserProvider or JsonRpcProvider` | **No** | You can provide your implementation of the provender for ethers |
| endpoints.web3 | `string OR string[]` | **No** | Your urls for connect to blockchain |
| endpoints.subgraph | `string` | **No** | stakewise subgraph url |
| endpoints.api | `string` | **No** | stakewise backend url |
| Name | Type | Required | Description |
|--------------------|------------------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| network | `Network` | **Yes** | Chain id |
| provider | `BrowserProvider or JsonRpcProvider` | **No** | You can provide your implementation of the provender for ethers |
| endpoints.web3 | `string OR Array<(string \| { url: string, headers: Headers })>` | **No** | Your 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.subgraph | `string` | **No** | stakewise subgraph url |
| endpoints.api | `string` | **No** | stakewise backend url |

## Quick Links

Expand Down
1 change: 1 addition & 0 deletions changelog/next-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Breaking change: Removed default rpc urls from the SDK. You must now provide the rpc urls or provider when creating a new SDK instance.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.3",
"version": "2.1.0",
"sideEffects": false,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class StakeWiseSDK {
constructor(options: StakeWise.Options) {
const config = configs[options.network]

if (!options.provider && !options.endpoints?.web3) {
throw new Error('Provider or endpoints.web3 should be provided')
}

const provider = options.provider || createProvider(options)

const contracts = createContracts({ provider, config })
Expand Down
2 changes: 0 additions & 2 deletions src/utils/apiUrls.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import configs from './configs'


const getWeb3Url = (options: StakeWise.Options) => options.endpoints?.web3 || configs[options.network].network.url
const getBackendUrl = (options: StakeWise.Options) => options.endpoints?.api || configs[options.network].api.backend
const getSubgraphqlUrl = (options: StakeWise.Options) => options.endpoints?.subgraph || configs[options.network].api.subgraph


export default {
getWeb3Url,
getBackendUrl,
getSubgraphqlUrl,
}
4 changes: 0 additions & 4 deletions src/utils/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const mainnet = {
chainId: Network.Mainnet,
hexadecimalChainId: '0x1',
blockExplorerUrl: 'https://etherscan.io',
url: 'https://mainnet.infura.io/v3/84842078b09946638c03157f83405213',
nativeCurrency: {
symbol: tokens.eth,
name: 'Ethereum',
Expand All @@ -22,7 +21,6 @@ const holesky = {
name: 'Holesky Testnet',
chainId: Network.Holesky,
hexadecimalChainId: '0x4268',
url: 'https://ethereum-holesky.publicnode.com/',
blockExplorerUrl: 'https://holesky.etherscan.io',
nativeCurrency: {
symbol: tokens.eth,
Expand All @@ -37,7 +35,6 @@ const chiado = {
name: 'Chiado Testnet',
chainId: Network.Chiado,
hexadecimalChainId: '0x27D8',
url: 'https://rpc.chiadochain.net',
blockExplorerUrl: 'https://gnosis-chiado.blockscout.com',
nativeCurrency: {
symbol: tokens.xdai,
Expand All @@ -52,7 +49,6 @@ const gnosis = {
name: 'Gnosis Chain',
chainId: Network.Gnosis,
hexadecimalChainId: '0x64',
url: 'https://rpc.gnosischain.com',
blockExplorerUrl: 'https://gnosisscan.io',
nativeCurrency: {
symbol: tokens.xdai,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getFetchRequest = (_url: string | StakeWise.UrlWithHeaders) => {
const createProvider = (options: StakeWise.Options) => {
const { network } = options

const urls = apiUrls.getWeb3Url(options)
const urls = options.endpoints?.web3 as string | string[]
const arrayUrls = typeof urls === 'string' ? [ urls ] : urls

if (arrayUrls.length === 1) {
Expand Down

0 comments on commit f3edc81

Please sign in to comment.