@oasisprotocol/sapphire-wagmi-v2
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@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,
});

Package Sidebar

Install

npm i @oasisprotocol/sapphire-wagmi-v2

Weekly Downloads

8

Version

2.0.0

License

Apache-2.0

Unpacked Size

20.7 kB

Total Files

9

Last publish

Collaborators

  • cedarmist
  • kostko
  • luka_oasisprotocol
  • oasisprotocol-bot
  • pro-wh
  • tjanez