-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinter.py
326 lines (259 loc) · 15.3 KB
/
Minter.py
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import asyncio
import re
import random
import string
import time
import web3.exceptions
from web3 import Web3
from logger import logger
from config import rpcs, nft_contract_abi, nft_ZoraCreator_contract_abi, ZoraNFTCreator_contract_abi, JSONExtensionRegistry_contract_abi
class Minter:
def __init__(self, pk):
self.pk = pk
self.collectionAddress = ""
async def mint(self, nft_address, nft_id: int):
web3 = Web3(Web3.HTTPProvider(rpcs["zora"], request_kwargs={'proxies':{'https': 'http://' + "pnorwyha:[email protected]:6094", 'http': 'http://' + "pnorwyha:[email protected]:6094"}}))
logger.info(f"Successfully connected to {rpcs['zora']}")
wallet_address = web3.eth.account.from_key(self.pk).address
wallet_balance = web3.eth.get_balance(wallet_address)
logger.info(f"Wallet address: {wallet_address}")
logger.info(f"Balance in ZORA network: {web3.from_wei(wallet_balance, 'ether')}")
try:
contract = web3.eth.contract(address=Web3.to_checksum_address(nft_address), abi=nft_contract_abi)
mint_tx = contract.functions.mint(
"0x169d9147dFc9409AfA4E558dF2C9ABeebc020182",
nft_id,
1,
Web3.to_hex(b'\x00' * 12 + Web3.to_bytes(hexstr=wallet_address)),
).build_transaction({
'from': web3.to_checksum_address(wallet_address),
'value': web3.to_wei(0.000777, 'ether'),
'gas': 150000,
#'gasPrice': web3.to_wei(0.005, 'gwei'),
'nonce': web3.eth.get_transaction_count(wallet_address),
'maxPriorityFeePerGas': web3.to_wei(0.005, 'gwei'),
'maxFeePerGas': web3.to_wei(0.005, 'gwei')
})
signed_mint_tx = web3.eth.account.sign_transaction(mint_tx, self.pk)
raw_mint_tx_hash = web3.eth.send_raw_transaction(signed_mint_tx.rawTransaction)
mint_tx_hash = web3.to_hex(raw_mint_tx_hash)
logger.info(f"Mint tx hash: {mint_tx_hash}")
for i in range(5):
await asyncio.sleep(5)
try:
mint_tx_receipt = web3.eth.wait_for_transaction_receipt(raw_mint_tx_hash, timeout=300)
if mint_tx_receipt.status == 1:
logger.info(f"Transaction: https://explorer.zora.energy/tx/{mint_tx_hash}")
else:
logger.error("Something went wrong while minting")
except web3.exceptions.TransactionNotFound as err:
logger.error(f"Something went wrong while minting: {err}")
continue
except Exception as err:
logger.error(f"Something went wrong while minting: {err}")
except Exception as err:
if "insufficient funds" and "have" in str(err):
have = int(re.search(r'have (\d+)', err.args[0]['message']).group(1))
want = int(re.search(r'want (\d+)', err.args[0]['message']).group(1))
gas = int(re.search(r'gas (\d+)', err.args[0]['message']).group(1))
logger.error(f"Insufficient funds for gas * price + value. Want: {want} Have: {have} Gas: {gas}")
elif "insufficient funds" in str(err):
logger.error(f"Insufficient funds for gas * price + value.")
else:
logger.error(f"Something went wrong: {err}")
async def purchase(self, nft_contract_address, value_to_send): # ZoraCreator1155Impl
web3 = Web3(Web3.HTTPProvider(rpcs["zora"], request_kwargs={
'proxies': {'https': 'http://' + "pnorwyha:[email protected]:6094",
'http': 'http://' + "pnorwyha:[email protected]:6094"}}))
logger.info(f"Successfully connected to {rpcs['zora']}")
wallet_address = web3.eth.account.from_key(self.pk).address
wallet_balance = web3.eth.get_balance(wallet_address)
logger.info(f"Wallet address: {wallet_address}")
logger.info(f"Balance in ZORA network: {web3.from_wei(wallet_balance, 'ether')}")
try:
contract = web3.eth.contract(address=Web3.to_checksum_address(nft_contract_address), abi=nft_ZoraCreator_contract_abi)
mint_tx = contract.functions.purchase(
1
).build_transaction({
'from': web3.to_checksum_address(wallet_address),
'value': web3.to_wei(value_to_send, 'ether'),
'gas': 150000,
# 'gasPrice': web3.to_wei(0.005, 'gwei'),
'nonce': web3.eth.get_transaction_count(wallet_address),
'maxPriorityFeePerGas': web3.to_wei(0.005, 'gwei'),
'maxFeePerGas': web3.to_wei(0.005, 'gwei')
})
signed_mint_tx = web3.eth.account.sign_transaction(mint_tx, self.pk)
raw_mint_tx_hash = web3.eth.send_raw_transaction(signed_mint_tx.rawTransaction)
mint_tx_hash = web3.to_hex(raw_mint_tx_hash)
logger.info(f"Mint tx hash: {mint_tx_hash}")
for i in range(5):
await asyncio.sleep(5)
try:
mint_tx_receipt = web3.eth.wait_for_transaction_receipt(raw_mint_tx_hash, timeout=300)
if mint_tx_receipt.status == 1:
logger.info(f"Transaction: https://explorer.zora.energy/tx/{mint_tx_hash}")
else:
logger.error("Something went wrong while minting")
except web3.exceptions.TransactionNotFound as err:
logger.error(f"Something went wrong while minting: {err}")
continue
except Exception as err:
logger.error(f"Something went wrong while minting: {err}")
except Exception as err:
if "insufficient funds" and "have" in str(err):
have = int(re.search(r'have (\d+)', err.args[0]['message']).group(1))
want = int(re.search(r'want (\d+)', err.args[0]['message']).group(1))
gas = int(re.search(r'gas (\d+)', err.args[0]['message']).group(1))
logger.error(f"Insufficient funds for gas * price + value. Want: {want} Have: {have} Gas: {gas}")
elif "insufficient funds" in str(err):
logger.error(f"Insufficient funds for gas * price + value.")
else:
logger.error(f"Something went wrong: {err}")
async def createERC721(self, name, symbol, mintPrice, mintLimitPerAddress, editionSize, royaltyBPS, description, imageURI): # ZoraNFTCreator
web3 = Web3(Web3.HTTPProvider(rpcs["zora"], request_kwargs={
'proxies': {'https': 'http://' + "pnorwyha:[email protected]:6094",
'http': 'http://' + "pnorwyha:[email protected]:6094"}}))
logger.info(f"Successfully connected to {rpcs['zora']}")
wallet_address = web3.eth.account.from_key(self.pk).address
wallet_balance = web3.eth.get_balance(wallet_address)
logger.info(f"Wallet address: {wallet_address}")
logger.info(f"Balance in ZORA network: {web3.from_wei(wallet_balance, 'ether')}")
try:
contract = web3.eth.contract(address=Web3.to_checksum_address("0xA2c2A96A232113Dd4993E8b048EEbc3371AE8d85"), abi=ZoraNFTCreator_contract_abi)
create_tx = contract.functions.createEdition(
name=name,
symbol=symbol,
editionSize=editionSize,
royaltyBPS=int(royaltyBPS*100), # royalty = 3% => royaltyBPS = 3*100
fundsRecipient=wallet_address,
defaultAdmin=wallet_address,
saleConfig=[web3.to_wei(mintPrice, 'ether'), mintLimitPerAddress, 1691759829, 18446744073709551615, 0, 0, b"0x000000000000000000000000000000"],
description=description,
animationURI="",
imageURI=imageURI
).build_transaction({
'from': web3.to_checksum_address(wallet_address),
'nonce': web3.eth.get_transaction_count(wallet_address),
'maxPriorityFeePerGas': web3.to_wei(0.005, 'gwei'),
'maxFeePerGas': web3.to_wei(0.005, 'gwei')
})
signed_create_tx = web3.eth.account.sign_transaction(create_tx, self.pk)
raw_create_tx_hash = web3.eth.send_raw_transaction(signed_create_tx.rawTransaction)
create_tx_hash = web3.to_hex(raw_create_tx_hash)
logger.info(f"Contract create tx hash: {create_tx_hash}")
for i in range(5):
await asyncio.sleep(5)
try:
create_tx_receipt = web3.eth.wait_for_transaction_receipt(raw_create_tx_hash, timeout=300)
if create_tx_receipt.status == 1:
log = create_tx_receipt['logs'][-1]
if log:
self.collectionAddress = "0x" + log['topics'][2].hex()[-40:]
logger.info(f"Created collection address: {self.collectionAddress}")
logger.info(f"Transaction: https://explorer.zora.energy/tx/{create_tx_hash}")
else:
logger.error("Something went wrong while contract creating")
except Exception as err:
logger.error(f"Something went wrong while contract creating: {err}")
except Exception as err:
if "insufficient funds" in str(err):
logger.error(f"Insufficient funds for gas * price + value.")
else:
logger.error(f"Something went wrong: {err}")
async def walletWarmUp1(self, nft_collection_address, uri): # Mint web page update emulating
web3 = Web3(Web3.HTTPProvider(rpcs["zora"], request_kwargs={
'proxies': {'https': 'http://' + "pnorwyha:[email protected]:6094",
'http': 'http://' + "pnorwyha:[email protected]:6094"}}))
logger.info(f"Successfully connected to {rpcs['zora']}")
wallet_address = web3.eth.account.from_key(self.pk).address
wallet_balance = web3.eth.get_balance(wallet_address)
logger.info(f"Wallet address: {wallet_address}")
logger.info(f"Balance in ZORA network: {web3.from_wei(wallet_balance, 'ether')}")
try:
contract = web3.eth.contract(address=Web3.to_checksum_address("0xABCDEFEd93200601e1dFe26D6644758801D732E8"),
abi=JSONExtensionRegistry_contract_abi)
warm_tx = contract.functions.setJSONExtension(
target=Web3.to_checksum_address(nft_collection_address),
uri=uri
).build_transaction({
'from': web3.to_checksum_address(wallet_address),
'nonce': web3.eth.get_transaction_count(wallet_address),
'maxPriorityFeePerGas': web3.to_wei(0.005, 'gwei'),
'maxFeePerGas': web3.to_wei(0.005, 'gwei')
})
signed_warm_tx = web3.eth.account.sign_transaction(warm_tx, self.pk)
raw_warm_tx_hash = web3.eth.send_raw_transaction(signed_warm_tx.rawTransaction)
warm_tx_hash = web3.to_hex(raw_warm_tx_hash)
logger.info(f"Warming up tx hash: {warm_tx_hash}")
for i in range(5):
await asyncio.sleep(5)
try:
create_tx_receipt = web3.eth.wait_for_transaction_receipt(raw_warm_tx_hash, timeout=300)
if create_tx_receipt.status == 1:
logger.info(f"Transaction: https://explorer.zora.energy/tx/{warm_tx_hash}")
else:
logger.error("Something went wrong while warming up")
except web3.exceptions.TransactionNotFound as err:
logger.error(f"Something went wrong while warming up: {err}")
continue
except Exception as err:
logger.error(f"Something went wrong while warming up: {err}")
except Exception as err:
if "insufficient funds" in str(err):
logger.error(f"Insufficient funds for gas * price + value.")
else:
logger.error(f"Something went wrong: {err}")
async def walletWarmUp2(self, nft_collection_address, publicSalePrice): # Mint price updating
web3 = Web3(Web3.HTTPProvider(rpcs["zora"], request_kwargs={
'proxies': {'https': 'http://' + "pnorwyha:[email protected]:6094",
'http': 'http://' + "pnorwyha:[email protected]:6094"}}))
logger.info(f"Successfully connected to {rpcs['zora']}")
wallet_address = web3.eth.account.from_key(self.pk).address
wallet_balance = web3.eth.get_balance(wallet_address)
logger.info(f"Wallet address: {wallet_address}")
logger.info(f"Balance in ZORA network: {web3.from_wei(wallet_balance, 'ether')}")
try:
contract = web3.eth.contract(address=Web3.to_checksum_address(nft_collection_address),
abi=nft_ZoraCreator_contract_abi)
warm_tx = contract.functions.setSaleConfiguration(
publicSalePrice=web3.to_wei(publicSalePrice, 'ether'),
maxSalePurchasePerAddress=4294967295,
publicSaleStart=int(time.time()),
publicSaleEnd=18446744073709551615,
presaleStart=0,
presaleEnd=0,
presaleMerkleRoot=b"0x000000000000000000000000000000"
).build_transaction({
'from': web3.to_checksum_address(wallet_address),
'nonce': web3.eth.get_transaction_count(wallet_address),
'maxPriorityFeePerGas': web3.to_wei(0.005, 'gwei'),
'maxFeePerGas': web3.to_wei(0.005, 'gwei')
})
signed_warm_tx = web3.eth.account.sign_transaction(warm_tx, self.pk)
raw_warm_tx_hash = web3.eth.send_raw_transaction(signed_warm_tx.rawTransaction)
warm_tx_hash = web3.to_hex(raw_warm_tx_hash)
logger.info(f"Warming up tx hash: {warm_tx_hash}")
for i in range(5):
await asyncio.sleep(5)
try:
create_tx_receipt = web3.eth.wait_for_transaction_receipt(raw_warm_tx_hash, timeout=300)
if create_tx_receipt.status == 1:
logger.info(f"Transaction: https://explorer.zora.energy/tx/{warm_tx_hash}")
else:
logger.error("Something went wrong while warming up")
except web3.exceptions.TransactionNotFound as err:
logger.error(f"Something went wrong while warming up: {err}")
continue
except Exception as err:
logger.error(f"Something went wrong while warming up: {err}")
except Exception as err:
if "insufficient funds" in str(err):
logger.error(f"Insufficient funds for gas * price + value.")
else:
logger.error(f"Something went wrong: {err}")
@staticmethod
def generateUri(length=50, prefix="baf"):
characters = string.ascii_lowercase + string.digits
random_chars = ''.join(random.choice(characters) for _ in range(length - len(prefix)))
return prefix + random_chars