Skip to content

Commit 089f661

Browse files
committed
Add Viem documentation
1 parent e134b49 commit 089f661

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

clients/js/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ const provider = sapphire.wrap(window.ethereum);
6868
window.ethereum = sapphire.wrap(window.ethereum); // If you're feeling bold.
6969
```
7070

71+
### Viem
72+
73+
```ts
74+
import { sapphireTestnet } from 'viem/chains';
75+
import * as sapphire from '@oasisprotocol/sapphire-paratime';
76+
77+
const provider = sapphire.wrap(window.ethereum! as EIP1193Provider);
78+
const walletClient = createWalletClient({
79+
chain: sapphireTestnet,
80+
transport: custom(provider),
81+
});
82+
```
83+
7184
## Troubleshooting
7285

7386
### `Error: missing provider (operation="getChainId", code=UNSUPPORTED_OPERATION, ...)`

docs/guide.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ can also use those with Sapphire; all you need to do is set your Web3 gateway UR
125125
You can find the details of the Oasis Sapphire Web3 gateway
126126
[here](/dapp/sapphire#web3-gateway).
127127

128+
#### Viem
129+
130+
Sapphire will mostly work with Viem out of the box. You will need to import
131+
the Sapphire client, define the `chain`, and wrap your `provider` before
132+
creating a [custom] transport.
133+
134+
[custom]: https://viem.sh/docs/clients/transports/custom.html
135+
136+
```ts
137+
import { sapphireTestnet } from 'viem/chains';
138+
import * as sapphire from '@oasisprotocol/sapphire-paratime';
139+
140+
const provider = sapphire.wrap(window.ethereum! as EIP1193Provider);
141+
const walletClient = createWalletClient({
142+
chain: sapphireTestnet,
143+
transport: custom(provider),
144+
});
145+
```
146+
128147
### Transactions & Calls
129148

130149
<!-- https://github.com/oasisprotocol/docs/blob/455980674563cad92ff1e1b62a7a5f2d4d6809f0/docs/general/images/architecture/client-km-compute.svg -->

0 commit comments

Comments
 (0)