Skip to content

Commit

Permalink
Add Viem documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aefhm committed Dec 1, 2023
1 parent 733f42e commit 2195fee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clients/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ const provider = sapphire.wrap(window.ethereum);
window.ethereum = sapphire.wrap(window.ethereum); // If you're feeling bold.
```

### Viem

```ts
import { sapphireTestnet } from 'viem/chains';
import * as sapphire from '@oasisprotocol/sapphire-paratime';

const provider = sapphire.wrap(window.ethereum! as EIP1193Provider);
const walletClient = createWalletClient({
chain: sapphireTestnet,
transport: custom(provider),
});
```

## Troubleshooting

### `Error: missing provider (operation="getChainId", code=UNSUPPORTED_OPERATION, ...)`
Expand Down
19 changes: 19 additions & 0 deletions docs/guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ can also use those with Sapphire; all you need to do is set your Web3 gateway UR
You can find the details of the Oasis Sapphire Web3 gateway
[here](/dapp/sapphire#web3-gateway).

#### Viem

Sapphire will mostly work with Viem out of the box. You will need to import
the Sapphire client, define the `chain`, and wrap your `provider` before
creating a [custom] transport.

[custom]: https://viem.sh/docs/clients/transports/custom.html

```ts
import { sapphireTestnet } from 'viem/chains';
import * as sapphire from '@oasisprotocol/sapphire-paratime';

const provider = sapphire.wrap(window.ethereum! as EIP1193Provider);
const walletClient = createWalletClient({
chain: sapphireTestnet,
transport: custom(provider),
});
```

### Transactions & Calls

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

0 comments on commit 2195fee

Please sign in to comment.