tornado-relayer/testTxManager.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-09-29 17:01:22 +02:00
const { toHex, toWei } = require('web3-utils')
const TxManager = require('./src/TxManager')
const { rpcUrl, privateKey } = require('./config')
2020-10-01 01:23:31 +02:00
const logHandles = require('why-is-node-running')
2020-09-29 22:13:45 +02:00
2020-10-01 01:23:31 +02:00
const manager = new TxManager({
2020-09-29 17:01:22 +02:00
privateKey,
rpcUrl,
2020-09-29 22:13:45 +02:00
config: {
CONFIRMATIONS: 1,
2020-09-29 22:13:45 +02:00
GAS_BUMP_INTERVAL: 1000 * 15,
},
2020-09-29 17:01:22 +02:00
})
2020-10-01 01:23:31 +02:00
const tx1 = {
value: 1,
gasPrice: toHex(toWei('1', 'gwei')),
to: '0xA43Ce8Cc89Eff3AA5593c742fC56A30Ef2427CB0',
}
const tx2 = {
2020-10-01 01:23:31 +02:00
value: 2,
// gasPrice: toHex(toWei('1', 'gwei')),
to: '0x0039F22efB07A647557C7C5d17854CFD6D489eF3',
2020-09-29 17:01:22 +02:00
}
async function main() {
2020-10-01 01:23:31 +02:00
const tx = manager.createTx(tx1)
setTimeout(() => tx.cancel(), 1000)
// setTimeout(() => tx.replace(tx2), 1000)
2020-10-01 01:23:31 +02:00
const receipt = await tx.send()
2020-09-29 17:01:22 +02:00
.on('transactionHash', (hash) => {
console.log('hash', hash)
})
2020-09-29 22:13:45 +02:00
.on('mined', (receipt) => {
console.log('Mined in block', receipt.blockNumber)
})
2020-09-29 17:01:22 +02:00
.on('confirmations', (confirmations) => {
console.log('confirmations', confirmations)
})
2020-10-01 01:23:31 +02:00
console.log('receipt', receipt)
// setTimeout(logHandles, 100)
2020-09-29 17:01:22 +02:00
}
main()