# Dumb Public Mint ERC 20代码update **Published by:** [0xcodinnnng](https://paragraph.com/@0xcodinnnng/) **Published on:** 2023-09-11 **URL:** https://paragraph.com/@0xcodinnnng/dumb-public-mint-erc-20-update ## Content import json import os import time from loguru import logger from web3 import Web3 from web3.middleware import geth_poa_middleware def transaction_maintain(from_address, contract_address, private_key, transaction_data='', nonce=None, gas_price=None, gas=None, eth_value=0, log=''): try: contract_address = w3.to_checksum_address(contract_address) from_address = w3.to_checksum_address(from_address) if nonce is None: nonce = w3.eth.get_transaction_count(from_address, 'pending') if gas_price is None: gas_price = w3.eth.gas_price * 1.1 gas_price = Web3.from_wei(int(gas_price), 'gwei') if gas is None: tx = { 'from': from_address, 'to': contract_address, 'gasPrice': w3.to_wei(gas_price, 'gwei'), 'chainId': 1, 'nonce': nonce, 'data': transaction_data, 'value': eth_value } gas = w3.eth.estimate_gas(tx) tx['gas'] = gas else: tx = { 'from': from_address, 'to': contract_address, 'gas': gas, 'gasPrice': w3.to_wei(gas_price, 'gwei'), 'chainId': 1, 'nonce': nonce, 'data': transaction_data, 'value': eth_value } signed_tx = w3.eth.account.sign_transaction(tx, private_key) tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) hash = w3.to_hex(tx_hash) logger.info(f'地址:{from_address} \n' f'contract_address:{contract_address} \n' f'{log}\n' f'hash:{hash}') return hash, 'success' except Exception as e: print(f'{from_address}:transaction error', e) logger.error(f'{from_address}:transaction error:{e}', e) def transaction_goerli(from_address, contract_address, private_key, transaction_data='', nonce=None, gas_price=None, gas=None, eth_value=0, log=''): try: contract_address = w3.to_checksum_address(contract_address) if nonce is None: nonce = w3.eth.get_transaction_count(from_address, 'pending') if gas_price is None: gas_price = w3.eth.gas_price * 1.1 gas_price = Web3.from_wei(int(gas_price), 'gwei') if gas is None: tx = { 'from': from_address, 'to': contract_address, 'gasPrice': w3.to_wei(gas_price, 'gwei'), 'chainId': 5, 'nonce': nonce, 'data': transaction_data, 'value': eth_value } gas = w3.eth.estimate_gas(tx) tx['gas'] = gas else: tx = { 'from': from_address, 'to': contract_address, 'gas': gas, 'gasPrice': w3.to_wei(gas_price, 'gwei'), 'chainId': 5, 'nonce': nonce, 'data': transaction_data, 'value': eth_value } signed_tx = w3.eth.account.sign_transaction(tx, private_key) tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) hash = w3.to_hex(tx_hash) # logger.info(f'地址:{from_address} \n' # f'contract_address:{contract_address} \n' # f'{log}\n' # f'hash:{hash}') logger.info(f'正在mint Dumb Contract ...hash:{hash}') return hash, 'success' except Exception as e: print(f'{from_address}:transaction error', e) logger.error(f'{from_address}:transaction error:{e}', e) def dumb_mint(contractId, amount): data = generate_data(contractId, amount) # 将字符串转换为字节串 bytes_data = data.encode('utf-8') # 将字节串转换为十六进制表示 transaction_data = bytes_data.hex() return transaction_data def generate_data(contractId, amount): # 校验contractId是否以'0x'开头 if not contractId.startswith('0x'): raise ValueError("contractId必须以'0x'开头") # 将amount补全为18个0 amount_str = str(amount) + '0' * 18 data = { "to": contractId, "data": {"function": "mint", "args": {"amount": amount_str}} } return f"data:application/vnd.esc;esip6=true,{json.dumps(data, separators=(',', ':'))}" if __name__ == '__main__': # 在https://app.infura.io/dashboard 注册免费账号,获取RPC,填写 w3 = Web3(Web3.HTTPProvider(RPC)) w3.middleware_onion.inject(geth_poa_middleware, layer=0) # 填入钱包地址和私钥,建议使用新钱包并只使用这一次,避免被盗 address = "" private_key = "" contract_address = "0x0000000000000000000000000000000000000000" # goerli测试网版——极速mint版 nonce = w3.eth.get_transaction_count(w3.to_checksum_address(address), 'pending') i = 0 while i < 10: # 在这里修改要mint的合约地址 transaction_data = dumb_mint("", 1000) transaction_goerli(address, contract_address, private_key, transaction_data=transaction_data, nonce=nonce, gas_price=None, gas=None, eth_value=0, log='goerli_dumb_mint') nonce += 1 i += 1 time.sleep(1) # # goerli测试网版——普通mint版 # i = 0 # while i < 10: # # 在这里修改要mint的合约地址 # transaction_data = dumb_mint("", 1000) # # hash = transaction_goerli(address, contract_address, private_key, transaction_data=transaction_data, nonce=None, # gas_price=None, gas=None, eth_value=0, log='goerli_dumb_mint') # i += 1 # time.sleep(5) # # eth主网版——极速mint版 # nonce = w3.eth.get_transaction_count(w3.to_checksum_address(address), 'pending') # i = 0 # while i < 10: # # 在这里修改要mint的合约地址 # transaction_data = dumb_mint("", 1000) # # hash = transaction_maintain(address, contract_address, private_key, transaction_data=transaction_data, nonce=nonce, # gas_price=None, gas=None, eth_value=0, log='maintain_dumb_mint') # i += 1 # nonce += 1 # time.sleep(1) # # # eth主网版——普通mint版 # i = 0 # while i < 10: # # 在这里修改要mint的合约地址 # transaction_data = dumb_mint("", 1000) # # hash = transaction_maintain(address, contract_address, private_key, transaction_data=transaction_data, nonce=None, # gas_price=None, gas=None, eth_value=0, log='maintain_dumb_mint') # i += 1 # time.sleep(5) ## Publication Information - [0xcodinnnng](https://paragraph.com/@0xcodinnnng/): Publication homepage - [All Posts](https://paragraph.com/@0xcodinnnng/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@0xcodinnnng): Subscribe to updates - [Twitter](https://twitter.com/0xcodinnnng): Follow on Twitter