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

ethers-redispatch-signer

v0.1.6

Published

ethers.js RedispatchSigner to redispatch transactions

Downloads

7

Readme

ethers-redispatch-signer

ethers.Signer subclass which accepts another signer in its constructor and wraps it where if the RedispatchSigner is used to send transactions, the transaction will be queued in the PersistenceAdapter instance associated wtih it, where it will be processed with higher gasPrice values during gas price spikes, until it is eventually mined.

Transaction objects returned by RedispatchSigner#sendTransaction implement an alternative tx.wait() where the return value is always the transaction that was actually mined no matter how many times it was redispatched, or it will be the transaction that was used to cancel the transaction.

await tx.cancel() is implemented to allow you to cancel the transaction. By default it will use a value for gasPrice that is twice the value of the value returned by signer.provider.getGasPrice()

You can also supply await tx.cancel({ multiplier: 3 }) or await tx.cancel({ gasPrice: ethers.utils.parseUnits('1000', 9) }) (those values are examples).

Be sure you do not cancel with a gasPrice which is lower than the exiting tx.gasPrice or cancel will throw.

Usage


const { RedispatchSigner } = require('ethers-redispatch-signer');

const signer = new RedispatchSigner(new JsonRpcProvider('http://localhost:8545').getSigner(0))
const redispatchingContract = contract.connect(signer);

const tx = await redispatchingContract.someFunction();
tx.wait().then((v) => {
  console.log('was cancelled: ' + Boolean(v.data === '0x')); // tx.wait() will resolve with either the cancel tx or the real tx, depending which one gets mined first
});
await tx.cancel();
// both txs will race .. probably this will get cancelled

await cancelTx.wait();

PersistenceAdapter

You can implement your own strategy around persisting the queue used by RedispatchSigner internally.

Create a subclass of PersistenceAdapter from require('@fauxbands/providers/redispatch-signer/persistence-adapter').PersistenceAdapter which implements iterateTransactions(function (watcher) { // logic }) as well as track(watcher) which accepts a TransactionWatcher object.

Create a subclass of RedispatchSigner which implements

static getDefaultPersistenceAdapter() which should return an instance of your new PersistenceAdapter class

When a transaction is sent through your signer, signer.persistence.track(signer.wrapTransaction(tx)) will be called. On every block update, iterateTranscations will be called and each transaction watcher will be passed in as an argument. The default implementation will call await watch.trigger(currentGasPrice)

If you subclass TransactionWatcher, you should implement static newGas(newGasPrice, oldGasPrice) which should return the gas price you want to use with a new transaction, and you should implement trigger(newGasPrice) which is where you should handle gasPrice updates

Further work

  • FilesystemPersistenceAdapter
  • RedisPersistenceAdapter