import { ethers } from 'ethers' ; export class EthersFastSubmitWallet extends ethers . Wallet { private nonce = 0 ; private gasPrice = 35e9 ; static async create ( privateKey , provider ) { const wallet = new EthersFastSubmitWallet ( privateKey , provider ) ; const nonce = await provider . getTransactionCount ( wallet . address , 'pending' ) ; wallet . setNonce ( nonce ) ; wallet . startGasPriceCheck ( ) ; return wallet ; } setNonce ( nonce ) { this . nonce = nonce ; } async startGasPriceCheck ( ) { const gasPrice = await this . provider . getGasPrice ( ) ; this . gasPrice = Math . round ( gasPrice . toNumber ( ) * 1.1 ) ; setTimeout ( this . startGasPriceCheck . bind ( this ) , 15000 ) ; } signMessage ( message ) { const hashmessage = ethers . utils . arrayify ( message ) ; return Promise . resolve ( super . signMessage ( hashmessage ) ) ; } sendTransaction ( transaction ) { transaction = ethers . utils . shallowCopy ( transaction ) ; transaction . nonce = this . nonce ; transaction . from = this . address ; transaction . gasPrice = this . gasPrice ; this . nonce ++ ; return this . provider . estimateGas ( transaction ) . then ( gasEstimate => { delete transaction . from ; return ethers . utils . populateTransaction ( transaction , this . provider , this . address ) . then ( tx => { return this . sign ( tx ) . then ( signedTransaction => { return this . provider . sendTransaction ( signedTransaction ) ; } ) ; } ) ; } ) ; } }