From 5bb22f002faf6ba003ad847d820e5d5a8fa6e53a Mon Sep 17 00:00:00 2001 From: Xi Zhang Date: Fri, 17 Nov 2023 15:12:50 -0600 Subject: [PATCH] Add Viem documentation --- clients/js/README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/clients/js/README.md b/clients/js/README.md index 3ee227ee9..0f62e335e 100644 --- a/clients/js/README.md +++ b/clients/js/README.md @@ -68,6 +68,44 @@ const provider = sapphire.wrap(window.ethereum); window.ethereum = sapphire.wrap(window.ethereum); // If you're feeling bold. ``` +### Viem + +```ts +import * as sapphire from '@oasisprotocol/sapphire-paratime'; + +const sapphireChainTestnet: Chain = { + id: sapphire.NETWORKS.testnet.chainId, + name: 'Sapphire', + network: 'sapphire', + nativeCurrency: { + decimals: 18, + name: 'Sapphire', + symbol: 'ROSE', + }, + rpcUrls: { + default: { + http: [sapphire.NETWORKS.testnet.defaultGateway], + }, + public: { + http: [sapphire.NETWORKS.testnet.defaultGateway], + }, + }, + blockExplorers: { + default: { + name: 'Sapphire Explorer (Testnet)', + url: sapphire.NETWORKS.testnet.defaultGateway + }, + }, + testnet: true, +}; + +const provider = sapphire.wrap(window.ethereum! as EIP1193Provider); +const walletClient = createWalletClient({ + chain: sapphireChainTestnet, + transport: custom(provider), +}); +``` + ## Troubleshooting ### `Error: missing provider (operation="getChainId", code=UNSUPPORTED_OPERATION, ...)`