2.0.1 • Published 10 months ago

@oasisprotocol/sapphire-viem-v2 v2.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

@oasisprotocol/sapphire-viem-v2

A plugin for Viem 2.x that encrypts transactions, gas estimations and calls to the Oasis Sapphire network to enable end-to-end encryption between the dApp and smart contracts.

Usage

First install the package.

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

Next you must ensure that any clients use the sapphireTransport() to encrypt any unsigned communication, for example when using hardhat-viem pass the transport parameter when constructing a Public Client:

import { sapphireLocalnet, sapphireTransport } from '@oasisprotocol/sapphire-viem-v2';

const publicClient = await hre.viem.getPublicClient({
	chain: sapphireLocalnet,
	transport: sapphireTransport()
});

The Sapphire transport will only encrypt transactions if connected to an in-browser wallet provider which accepts eth_sendTransaction calls. To encrypt transactions when using a local wallet client you must not only provide the transport parameter, but must also wrap the wallet client, as such:

import { sapphireLocalnet, sapphireTransport, wrapWalletClient } from '@oasisprotocol/sapphire-viem-v2';

const walletClient = await wrapWalletClient(createWalletClient({
	account,
	chain: sapphireLocalnet,
	transport: sapphireTransport()
}));