JSPM

@oasisprotocol/sapphire-wagmi-v2

2.0.0-alpha.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 26
  • Score
    100M100P100Q76911F
  • License Apache-2.0

Wagmi & Viem support for the Oasis Sapphire ParaTime.

Package Exports

  • @oasisprotocol/sapphire-wagmi-v2

Readme

@oasisprotocol/sapphire-wagmi-v2

A plugin for Wagmi v2 that wraps the providers connected to the Sapphire network to enable end-to-end encryption for transactions, view calls and gas estimations

Usage

First install the package.

npm install @oasisprotocol/sapphire-wagmi-v2 wagmi@2.x viem@2.x

Next, in your Wagmi config definition, setup Sapphire wrapping for the injected provide using injectedWithSapphire() and then define the transports using the sapphireTransport() function.

import { createConfig } from "wagmi";
import { sapphire, sapphireTestnet } from "wagmi/chains";
import {
    injectedWithSapphire,
    sapphireTransport,
} from "@oasisprotocol/sapphire-wagmi-v2";

export const config = createConfig({
    multiInjectedProviderDiscovery: false,
    chains: [sapphire, sapphireTestnet],
    connectors: [injectedWithSapphire()],
    transports: {
        [sapphire.id]: sapphireTransport(),
        [sapphireTestnet.id]: sapphireTransport()
    },
});

Please note that while EIP-6963 (Multi Injected Provider Discovery) is supported by Wagmi it is only possible to wrap the default injected EIP-1193 compatible provider. For this reason you must disable MIPD support in the Wagmi configuration as additional discovered providers will not be Sapphire wrapped.

    multiInjectedProviderDiscovery: false,

To connect to your sapphire-localnet instance, define a custom chain:

import { defineChain } from "viem";

const sapphireLocalnet = defineChain({
    id: 0x5afd,
    name: "Oasis Sapphire Localnet",
    network: "sapphire-localnet",
    nativeCurrency: { name: "Sapphire Local Rose", symbol: "TEST", decimals: 18 },
    rpcUrls: {
        default: {
            http: ["http://localhost:8545"],
        },
    },
    testnet: true,
});