-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
55 lines (50 loc) · 1.32 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { StuckTransactionsCanceller } from './index.js'
import { ethers } from 'ethers'
import assert from 'node:assert'
const { WALLET_SEED } = process.env
assert(WALLET_SEED, 'WALLET_SEED required')
const provider = new ethers.JsonRpcProvider(
'https://api.calibration.node.glif.io/'
)
const signer = ethers.Wallet.fromPhrase(WALLET_SEED).connect(provider)
const storage = new Map()
const stuckTransactionsCanceller = new StuckTransactionsCanceller({
store: {
set ({ hash, timestamp, from, maxPriorityFeePerGas, gasLimit, nonce }) {
storage.set(hash, {
hash,
timestamp,
from,
maxPriorityFeePerGas,
gasLimit,
nonce
})
},
list () {
return [...storage.values()]
},
remove (hash) {
storage.delete(hash)
}
},
log (str) {
console.log(str)
},
async sendTransaction (tx) {
return signer.sendTransaction(tx)
}
})
const tx = await signer.sendTransaction({
to: '0x000000000000000000000000000000000000dEaD',
value: 1
})
console.log({
hash: tx.hash,
nonce: tx.nonce,
gasLimit: tx.gasLimit,
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
maxFeePerGas: tx.maxFeePerGas
})
await stuckTransactionsCanceller.addPending(tx)
await stuckTransactionsCanceller.cancelOlderThan(0)
await stuckTransactionsCanceller.cancelOlderThan(0)