|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
from web3 import Web3 |
|
import hashlib |
|
import requests |
|
import re |
|
import time |
|
import os |
|
|
|
|
|
|
|
approved_use = False |
|
|
|
|
|
|
|
def is_valid_eth_address(address): |
|
if re.match("^0x[0-9a-fA-F]{40}$", address): |
|
return True |
|
return False |
|
|
|
|
|
|
|
def is_valid_eth_private_key(private_key): |
|
if re.match("^[0-9a-fA-F]{64}$", private_key): |
|
return True |
|
return False |
|
|
|
|
|
|
|
def validate_input(data_str): |
|
if re.search(r'[A-Z\s\n]', data_str): |
|
return False |
|
return True |
|
|
|
|
|
|
|
def text_to_hex(text): |
|
return ''.join(format(byte, '02x') for byte in text.encode('utf-8')) |
|
|
|
|
|
|
|
def sha256(input_string): |
|
sha256 = hashlib.sha256() |
|
sha256.update(input_string.encode('utf-8')) |
|
return sha256.hexdigest() |
|
|
|
|
|
|
|
def check_content_exists(sha): |
|
|
|
endpoint = f"/ethscriptions/exists/{sha}" |
|
response = requests.get('https://mainnet-api.ethscriptions.com/api' + endpoint) |
|
|
|
if response.status_code == 200: |
|
return response.json()['result'] |
|
|
|
|
|
|
|
def send_transaction(w3, account_address, private_key, chain_id, gas_price, input_data, current_nonce): |
|
|
|
|
|
tx = { |
|
'chainId': chain_id, |
|
'gas': 25000, |
|
'gasPrice': gas_price, |
|
'nonce': current_nonce, |
|
'to': account_address, |
|
'value': 0, |
|
'data': text_to_hex(input_data), |
|
} |
|
|
|
|
|
signed_tx = w3.eth.account.sign_transaction(tx, private_key) |
|
|
|
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) |
|
|
|
st.toast(f'{input_data}', icon='✅') |
|
|
|
return input_data, tx_hash.hex() |
|
|
|
|
|
|
|
st.set_page_config(page_title="EthPen - 批量题写代币铭文", page_icon="🪙", layout='centered', initial_sidebar_state='auto') |
|
|
|
|
|
st.subheader(r'🪙 :rainbow[EthPen - 代币铭文批量题写]', anchor=False, divider='rainbow') |
|
|
|
|
|
st.markdown('### 在开始使用前,请仔细阅读相关说明,并在确认无误后打上 ✅。感谢您的理解与配合。') |
|
|
|
open_source = st.checkbox('我们已将网站代码完全开源。您可以访问并仔细阅读此页面的源码:[3_🪙_ 批量题写代币铭文.py](https://huggingface.co/spaces/Ethscriptions/eths/tree/main/pages)',) |
|
|
|
ask_ai = st.checkbox('如果你对此代码存有疑虑,建议你利用如 [OpenAI - ChetGPT](https://chat.openai.com/)、[Google - Bard](https://bard.google.com/)、[Anthropic - Claude](https://claude.ai/)、[抖音 - 豆包](https://www.doubao.com/)、[百度 - 文心一言](https://yiyan.baidu.com/)、[阿里 - 通义千问](https://qianwen.aliyun.com/) 等知名 AI 平台进行问询,这可以帮助你判断代码是否含有恶意内容。',) |
|
|
|
huggingface = st.checkbox('复制我们的代码,你同样可以在 [HuggingFace](https://HuggingFace.co) 上搭建专属于你的域名铭文批量题写工具。',) |
|
|
|
site = st.checkbox('请务必确保你正在访问的是 **[EthPen.com](https://ethpen.com)** 网站。我们保证站内代码不包含窃取私钥或其他恶意行为,你可以安心使用。',) |
|
|
|
use = st.checkbox('在使用过程中,请按照提示准确地填写信息,这样可以确保程序的顺畅运行。',) |
|
|
|
wallet = st.checkbox('为了安全起见,我们建议您使用备用账号(小号)并确保账号中不存放大额资金。',) |
|
|
|
test = st.checkbox('首次使用时,我们建议您先在测试网络中操作。确认一切无误后,再切换至主网络使用。',) |
|
|
|
feedback = st.checkbox('若您在使用过程中遇到问题,请及时向我们反馈。我们明白程序可能存在不完善之处,并且我们的能力也有限。真心希望得到各位程序员大佬的指导和交流。',) |
|
|
|
if open_source and ask_ai and huggingface and site and use and wallet and test and feedback: |
|
approved_use = True |
|
else: |
|
approved_use = False |
|
|
|
if approved_use: |
|
|
|
st.markdown('## 批量题写代币铭文') |
|
|
|
|
|
net_options = { |
|
'1': 'Mainnet', |
|
'5': 'Goerli', |
|
'11155111': 'Sepolia' |
|
} |
|
selected_option = st.selectbox( |
|
'**网络 ID**', |
|
list(net_options.keys()), |
|
format_func=lambda x: f"{x} ({net_options[x]})" |
|
) |
|
chain_id = int(selected_option) |
|
|
|
|
|
token_eth_prc_url = st.text_input( |
|
f'**Ethereum PRC 链接**:选填,你可以去 [infura.io](https://app.infura.io/) 或者 [alchemy.com](https://alchemy.com/) 免费申请一个', |
|
f'https://{net_options[str(chain_id)]}.infura.io/v3/eab7f935b9af45e1a54f7d7ed06c5206') |
|
w3 = Web3(Web3.HTTPProvider(f'{token_eth_prc_url}')) |
|
|
|
|
|
current_account_index = 0 |
|
|
|
transaction_results = [] |
|
|
|
accounts = [] |
|
|
|
nonces = {} |
|
|
|
|
|
multipl_accounts = st.toggle('启用**多账户**操作') |
|
if multipl_accounts: |
|
|
|
account_list = st.text_area(f'输入多个 **ETH 地址及其对应的私钥**,用英文逗号分隔(,),如下:地址,私钥') |
|
if account_list: |
|
for line in account_list.split('\n'): |
|
if ',' in line: |
|
address, key = line.split(',') |
|
if is_valid_eth_address(address) and is_valid_eth_private_key(key): |
|
current_nonce = w3.eth.get_transaction_count(address) |
|
nonces[address] = current_nonce |
|
accounts.append((address.strip(), key.strip())) |
|
else: |
|
st.error(f"地址 {address} 或私钥 {key} 无效,请检查!") |
|
st.stop() |
|
else: |
|
st.error(f"输入格式错误,请确保每行包含一个地址和一个私钥,并使用英文逗号分隔(,)。错误行:**{line}**") |
|
st.stop() |
|
else: |
|
account_address = st.text_input('填写你的 **ETH 地址**:') |
|
private_key = st.text_input('填写你的 **ETH 地址对应的私钥**:', type="password") |
|
if account_address and private_key: |
|
if is_valid_eth_address(account_address) and is_valid_eth_private_key(private_key): |
|
current_nonce = w3.eth.get_transaction_count(account_address) |
|
nonces[account_address] = current_nonce |
|
accounts.append((account_address.strip(), private_key.strip())) |
|
else: |
|
st.error("地址或私钥无效,请检查!") |
|
st.stop() |
|
|
|
|
|
token_protocol = st.text_input('填写需要题写代币铭文协议 **Protocol(p)**:', 'erc-20') |
|
token_operation = st.text_input('填写需要题写代币铭文操作 **Operation(op)**:', 'mint') |
|
token_ticker = st.text_input('填写需要题写代币铭文简称 **Ticker(tick)**:') |
|
token_min_id = st.number_input('填写需要题写代币铭文范围的**最小 ID(id)**:', min_value=1, value=1, step=1) |
|
token_max_id = st.number_input('填写需要题写代币铭文范围的**最大 ID(id)**:', value=21000, step=1) |
|
token_amount = st.number_input('填写需要题写代币铭文数量 **Amount(amt)**:', min_value=1, value=1000, step=1) |
|
st.markdown('###### 预览代币铭文:') |
|
st.code( |
|
f'data:,{{"p":"{token_protocol}","op":"{token_operation}","tick":"{token_ticker}","id":"{token_min_id}","amt":"{token_amount}"}}', |
|
language="json", line_numbers=False) |
|
|
|
if not validate_input( |
|
f'data:,{{"p":"{token_protocol}","op":"{token_operation}","tick":"{token_ticker}","id":"{token_min_id}","amt":"{token_amount}"}}'): |
|
st.warning("**请注意**:通常代币铭文文本里不能包含空格、换行符,而且所有的字母都必须为小写。") |
|
|
|
token_check = st.toggle('题写前**检查是否被题写** `主网` `查重`') |
|
|
|
if token_check: |
|
token_check = True |
|
else: |
|
token_check = False |
|
sleep_3s = st.toggle('每次完成交易后暂停 3 秒') |
|
|
|
if sleep_3s: |
|
sleep_3s = True |
|
else: |
|
sleep_3s = False |
|
|
|
|
|
if st.button(f'开始**发送交易**'): |
|
if not accounts or not token_protocol or not token_operation or not token_ticker: |
|
st.error(f'请正确谨慎地填写内容,每一项都**不应留空**。') |
|
st.stop() |
|
else: |
|
st.toast('看起来你输入的内容均无没有问题!', icon='🥳') |
|
|
|
st.toast(f'开始任务,需要题写的铭文总量为:{token_max_id - token_min_id + 1}', icon='😎') |
|
|
|
|
|
for the_id in range(token_min_id, token_max_id + 1): |
|
|
|
address, key = accounts[current_account_index] |
|
|
|
input_data = f'data:,{{"p":"{token_protocol}","op":"{token_operation}","tick":"{token_ticker}","id":"{the_id}","amt":"{token_amount}"}}' |
|
|
|
gas_price = w3.eth.gas_price |
|
|
|
if token_check: |
|
|
|
if check_content_exists(sha256(input_data)): |
|
|
|
st.toast(f'{input_data} 已经被题写!', icon='☹️') |
|
else: |
|
|
|
|
|
data, tx_hash = send_transaction(w3, address, key, chain_id, gas_price, input_data, nonces[address]) |
|
|
|
transaction_results.append(f"{address} | {data} | Transaction Hash: {tx_hash}") |
|
|
|
nonces[address] += 1 |
|
else: |
|
|
|
|
|
data, tx_hash = send_transaction(w3, address, key, chain_id, gas_price, input_data, nonces[address]) |
|
|
|
transaction_results.append(f"{address} | {data} | Transaction Hash: {tx_hash}") |
|
|
|
nonces[address] += 1 |
|
|
|
current_account_index = (current_account_index + 1) % len(accounts) |
|
|
|
if sleep_3s: |
|
time.sleep(3) |
|
st.toast(f'所有任务已经完成。', icon='🎉') |
|
|
|
st.balloons() |
|
|
|
st.code('\n'.join(transaction_results)) |
|
else: |
|
st.error('# 阅读并打勾 ✅ 后方可使用。') |