说明:
1、通过提前分地址,批量让地址打铭文以达成极速的诉求,所以想要极速效果,需要提前分地址+分钱,舍不得分很多号以及gas的盆友用自己一个号打就好了
2、接口用的是etch官网的接口,不知道未来还能不能用,且不保证百分百打到,但我一般命中率有70%以上,需要提前知悉
3、运行一次会打分地址数的铭文给接收地址,我一般是分100个号,预期打200个,就运行2-3次
import json
import concurrent.futures
import time
import requests
from loguru import logger
from web3 import Web3
from web3.middleware import geth_poa_middleware
def transaction_base(from_address, contract_address, from_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
}
private_key = from_private_key
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:
logger.error(f'{from_address}:transaction error, {e}', e)
def ethscribe(tick, p='erc-20'):
# 请求的URL
url = f'https://www.etch.market/api/ethscriptions/erc20/ethscribe?p={p}&tick={tick}'
while True:
try:
# 发送GET请求
response = requests.get(url)
# 检查响应状态码
if response.status_code == 200:
data = json.loads(response.text)
result = data["data"]["data"]
return result
else:
print("get ethscribe data fail")
time.sleep(1)
except Exception as e:
logger.error(f'get ethscribe data error{e}')
def batch_pool_execute_ethscribe(function, file_name, to_address, tick):
with open(file_name, "r") as fp:
data = json.load(fp)
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
futures = [executor.submit(function, line["address"], to_address, line["private_key"], tick) for line in data]
def transaction_ethscribe(address, to_address, private_key, tick, log=''):
transaction_data = ethscribe(tick)
transaction_base(address, to_address, private_key, transaction_data, nonce=None,
gas_price=None, gas=33516, eth_value=0, log=log)
if __name__ == '__main__':
# 申请主网RPC:https://app.infura.io/dashboard 注册免费账号,获取RPC,填写
w3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/xxxxxxx"))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)
# 在该py文件的目录下,创建address.json文件,分别在后面的双引号内填入地址和私钥,
# 建议提前分10-100个地址不等,分的越多,一次打的越多,往里面存十几u够用,如果日常用的话可以多放点预留
# 文件格式如下
# [
# {"address": "", "private_key": ""},
# {"address": "", "private_key": ""},
# {"address": "", "private_key": ""}
# ]
file_name = "address.json"
# 把铭文打给哪个地址,代打或分号打用
to_address = ''
batch_pool_execute_ethscribe(transaction_ethscribe, file_name, to_address, 'facet')
