npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cryptoguysclub/sapphireparatime

v1.1.5

Published

The Sapphire ParaTime Web3 integration library.

Downloads

24

Readme

Sapphire ParaTime Compat Lib

@oasisprotocol/sapphire-paratime makes it easy to port your dapp to the Sapphire ParaTime by wrapping your existing ethers.Provider/window.ethereum/web3.providers.*. Once you wrap your provider, you can use Sapphire just like you would use Ethereum.

If your dapp doesn't port in under 10 minutes, it's a bug!
If you have more than a little trouble, please file an issue.
There should be no reason not to use the Sapphire ParaTime!

Usage

After installing this library, find your Ethereum provider and wrap it using sapphire.wrap. Below are some examples for the most kinds of providers.

Hardhat

Try the @oasisprotocol/sapphire-hardhat Hardhat plugin for extra convenience. Place this line at the top of your hardhat.config.ts.

import '@oasisprotocol/sapphire-hardhat';
// All other Hardhat plugins must come below.

ethers.js

import { ethers } from 'ethers';
import * as sapphire from '@oasisprotocol/sapphire-paratime';

// In the browser via `window.ethereum`.
const signer = sapphire.wrap(
  new ethers.providers.Web3Provider(window.ethereum).getSigner(),
);

// In Node via `ethers.Wallet`.
const signer = sapphire
  .wrap(new ethers.Wallet('0x0a5155afec0de...'))
  .connect(ethers.getDefaultProvider(sapphire.NETWORKS.testnet.defaultGateway));

// Just a provider, no signer.
const provider = sapphire.wrap(
  ethers.getDefaultProvider(sapphire.NETWORKS.testnet.defaultGateway),
);

web3.js

import Web3 from 'web3';
import * as sapphire from '@oasisprotocol/sapphire-paratime';

web3.setProvider(sapphire.wrap(web3.currentProvider));

EIP-1193

import * as sapphire from '@oasisprotocol/sapphire-paratime';

const provider = sapphire.wrap(window.ethereum);
window.ethereum = sapphire.wrap(window.ethereum); // If you're feeling bold.

Troubleshooting

Error: missing provider (operation="getChainId", code=UNSUPPORTED_OPERATION, ...)

Explanation: When you first make a transaction or call using a wrapped signer or provider, this library will automatically fetch the runtime public key from the Web3 gateway using your connected provider. If you've wrapped just a signer (e.g., ethers.Wallet), then you'll see this error.

Fix: The simplest thing to do is connect a provider. Alternatively, you can pass in a pre-initialized Cipher object as the second argument to wrap; and then also generate signed queries manually using the overrides parameter to SignedCallDataPack.make. This latter approach is not recommended except for the most custom of use cases, however.

MetaMask keeps popping up asking me to sign messages

Explanation: The default behavior of the Sapphire ParaTime compatibility library is to sign calls such that msg.sender can be authenticated during eth_call and eth_estimateGas. This is useful for methods in contracts that do identity-based access control. For better UX in the browser, you should only make signed calls when necessary.

Fix: The Sapphire ParaTime compat lib will not sign calls when the from address is address(0). For Web3.js you can pass { from: 0x${'0'.repeat(40)} } as the final arg to Contract.method().call (ref). For Ethers.js please read the next section.

Contract with a Signer cannot override from (operation="overrides.from", code=UNSUPPORTED_OPERATION, ...)

Explanation: Ethers prevents overriding from when using a Signer for safety reasons.

Fix: Create a new Contract instance but do not connect it to a signer–just a provider. Use that for unsigned queries instead.

See Also