-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmintBot.html
More file actions
180 lines (150 loc) · 6.68 KB
/
mintBot.html
File metadata and controls
180 lines (150 loc) · 6.68 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
layout: default
---
<div class="container">
<h1>Mint Bot</h1>
<div id="wallet"></div>
<div class="p-5 mb-4 bg-light rounded-3" id="startForn">
<div class="container-fluid py-5">
<div class="form-group row">
<label for="watchedVar" class="col-sm-2 col-form-label">Watched Variable</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="watchedVar" value="publicSaleActive" required>
</div>
</div>
<div class="form-group row">
<label for="targetVal" class="col-sm-2 col-form-label">Target Value</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="targetVal" value="true" required>
</div>
</div>
<div class="form-group row">
<label for="mintFunction" class="col-sm-2 col-form-label">Mint Function Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="mintFunction" value="mint" required>
</div>
</div>
<div class="form-group row">
<label for="pricePerNft" class="col-sm-2 col-form-label">Price Per NFT (ETH)</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="pricePerNft" value="0.01" required>
</div>
</div>
<div class="form-group row">
<label for="nbNftsToMint" class="col-sm-2 col-form-label">How Many to Mint</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="nbNftsToMint" value="1" required>
</div>
</div>
<div class="form-group row">
<label for="maxBaseGasGwei" class="col-sm-2 col-form-label">Max Base Gas (Gwei)</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="maxBaseGasGwei" value="75" required>
</div>
</div>
<div class="form-group row">
<label for="extraGasGwei" class="col-sm-2 col-form-label">Extra Gas (Gwei)</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="extraGasGwei" value="5" required>
</div>
</div>
<div class="form-group row">
<label for="priorityFeeGwei" class="col-sm-2 col-form-label">Priority fee (Gwei)</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="priorityFeeGwei" value="2" required>
</div>
</div>
<div class="form-group row">
<label for="minBalanceETH" class="col-sm-2 col-form-label">Minimum Balance (ETH)</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="minBalanceETH" value="0.01" required>
</div>
</div>
<div class="form-group row">
<label for="contractAddress" class="col-sm-2 col-form-label">Contract Address</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="contractAddress" value="" required>
</div>
</div>
<hr/>
<button id="startButton" class="btn btn-primary btn-lg" type="button">Start</button>
</div>
</div>
</div>
{% include jquery.html %}
<script type="module">
import { ethers } from "./assets/ethers-5.4.esm.min.js";
async function startBot() {
$("#startForn").hide();
// Config
const watchedVar = $("#watchedVar").val()
const targetVal = ($("#watchedVar").val() == "true") ? true : ($("#watchedVar").val() == "false") ? false : $("#watchedVar").val()
const mintFunction = $("#mintFunction").val()
const pricePerNft = $("#pricePerNft").val()
const nbNftsToMint = $("#nbNftsToMint").val()
const maxBaseGasGwei = $("#maxBaseGasGwei").val()
const extraGasGwei = $("#extraGasGwei").val()
const priorityFeeGwei = $("#priorityFeeGwei").val()
const minBalanceETH = $("#minBalanceETH").val()
// Provider
const provider = new ethers.providers.Web3Provider(window.ethereum)
// Signer
await provider.send("eth_requestAccounts", [])
const signer = provider.getSigner()
const balance = await signer.getBalance()
const address = await signer.getAddress()
$("#wallet").html("<p>" + address + " " + balance + "</p>")
// Contract - 0xf7479F9527c57167caff6386DAA588B7BF05727f
const contractAddress = $("#contractAddress").val()
$.ajax({
dataType: "json",
url: "https://api.etherscan.io/api?module=contract&action=getabi&address=" + contractAddress,
success: function(result) {
const contractABI = result.result;
const mintContract = new ethers.Contract(contractAddress, contractABI, signer);
let id = setInterval(botLoop, 10000, mintContract, watchedVar, targetVal, mintFunction, pricePerNft, nbNftsToMint, maxBaseGasGwei, extraGasGwei, priorityFeeGwei, minBalanceETH); // Start loop every 10 seconds
}
});
}
async function botLoop(mintContract, watchedVar, targetVal, mintFunction, pricePerNft, nbNftsToMint, maxBaseGasGwei, extraGasGwei, priorityFeeGwei, minBalanceETH) {
const currentValue = await mintContract[watchedVar]();
if (currentValue == targetVal) {
const balance = await signer.getBalance()
if (Number(ethers.utils.formatEther(balance)) > Number(minBalanceETH)) {
const gasPrice = await ........................
if (Number(ethers.utils.formatUnits(gasPrice, "gwei")) < Number(maxBaseGasGwei)) {
const extraGas = Number(ethers.utils.formatUnits(gasPrice, "gwei")) + Number(extraGwei)
const priceTotal = String(Number(pricePerNft) * Number(nbNftsToMint))
let transaction = {
value: ethers.utils.parseEther(priceTotal),
maxPriorityFeePerGas: ethers.utils.parseUnits(priorityFeeGwei, "gwei"),
maxFeePerGas: ethers.utils.parseUnits(extraGas.toFixed(9), "gwei"),
type: 2
}
// Estimate Gas
const gasLimit = await mintContract.estimateGas[mintFunction](nbNftsToMint, transaction)
if (gasLimit) {
console.log("MINT!! - Gas: " + ethers.utils.formatUnits(gasPrice, "gwei") + " Gwei")
clearInterval(id) // Stop loop - but keep going below..
// Mint!!
//const tx = await mintContract[mintFunction](nbNftsToMint, transaction)
//await tx.wait()
console.log("Done!", tx)
}
} else {
console.log("Gas too high: " + ethers.utils.formatUnits(gasPrice, "gwei") + " Gwei")
}
} else {
console.log("Not enough ETH: " + ethers.utils.formatEther(balance) + " Eth")
clearInterval(id) // Stop loop
}
} else {
console.log("currentValue: " + currentValue)
}
}
$(document).ready(function() {
$("#startButton").click(function() {
startBot()
});
});
</script>