-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmine.js
72 lines (61 loc) · 1.86 KB
/
mine.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require('dotenv').config()
const { createPublicClient, createWalletClient, http } = require('viem')
const { privateKeyToAccount } = require('viem/accounts')
const { blast } = require('viem/chains')
const publicClient = createPublicClient({
chain: blast,
transport: http(process.env.RPC)
})
const privateKey = process.env.PRIVATE_KEY.startsWith('0x') ? process.env.PRIVATE_KEY : `0x${process.env.PRIVATE_KEY}`
const account = privateKeyToAccount(privateKey)
const walletClient = createWalletClient({
chain: blast,
transport: http(process.env.RPC),
account
})
const HYPERSOUND_ADDRESS = '0xF8797dB8a9EeD416Ca14e8dFaEde2BF4E1aabFC3'
const HYEPRSOUND_ABI = require('./abi.json')
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))
async function mine() {
try {
let hash
const mineAmount = process.env.CALLS_PER_MINE_TX
if (mineAmount === '1') { // mine one with mine()
hash = await walletClient.writeContract({
address: HYPERSOUND_ADDRESS,
abi: HYEPRSOUND_ABI,
functionName: 'mine',
args: ['0x'],
account,
gas: BigInt(200000)
})
} else { // mine multiple with mineBatch()
hash = await walletClient.writeContract({
address: HYPERSOUND_ADDRESS,
abi: HYEPRSOUND_ABI,
functionName: 'mineBatch',
args: [BigInt(mineAmount), '0x'],
account,
gas: BigInt(27000000)
})
}
console.log('Mine transaction sent. Hash:', hash)
const receipt = await publicClient.waitForTransactionReceipt({ hash })
console.log('Mine transaction confirmed')
} catch (e) {
console.error('An error occurred while executing the transaction', e)
}
}
let isRunning = true
async function start() {
while (isRunning) {
await mine()
await sleep(60000 / parseInt(process.env.MINE_TX_PER_MINUTE))
}
}
start()
// Handle graceful shutdown for docker
process.on('SIGINT', () => {
console.log('Shutting down...')
isRunning = false
})