Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs update] update #237

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ class StakeWiseSDK {
}

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

provider.getSigner = async function (address?: string) {
const providerError = 'To send this transaction, please provide BrowserProvider to the StakeWiseSDK'

try {
const signer = await originalGetSigner.bind(this)(address)

return signer
}
catch (error) {
throw new Error(providerError)
}
}

const contracts = createContracts({ provider, config })

Expand Down
52 changes: 44 additions & 8 deletions website/setup/installation-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ webpackConfig.module.rules.push(
}
)
```
#### Create SDK instance:
#### 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`

```typescript
import { StakeWiseSDK, Network } from '@stakewise/v3-sdk'
Expand All @@ -31,16 +34,49 @@ const sdk = new StakeWiseSDK({
web3: 'https://mainnet.infura.io/v3/...',
},
})
```

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

```typescript
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](https://stackblitz.com/edit/stakewise-sdk?file=src%2Fcomponents%2Futil%2Findex.ts,src%2Fcomponents%2FConnect.tsx,src%2Fcomponents%2FSdkContext.tsx,src%2Fcomponents%2Futil%2FinitContext.ts,src%2Fwagmi.ts,src%2FApp.tsx,src%2Fcomponents%2FConnectWallet.tsx,src%2Fcomponents%2FAccount.tsx).

```typescript
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:

| 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 |
| Name | Type | Required | Description |
|--------------------|--------------------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| network | `Network` | **Yes** | Chain id |
| provider | `BrowserProvider` or `JsonRpcProvider` | **No** | You can provide your implementation of the provender for ethers. This parameter is required to send transactions. |
| 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 |

Loading