Spaces:
Sleeping
Sleeping
Commit
·
853f7c8
1
Parent(s):
5c33ba8
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,114 +67,85 @@ def send_transaction(w3, account_address, private_key, chain_id, input_data, the
|
|
| 67 |
# 发送签名后的交易并获取交易哈希
|
| 68 |
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
| 69 |
# 打印结果信息
|
| 70 |
-
st.toast(f'{the_id}', icon='✅')
|
| 71 |
# 返回铭文还有交易哈希
|
| 72 |
return input_data, tx_hash.hex()
|
| 73 |
except Exception as e:
|
| 74 |
-
st.toast(f'{the_id}', icon='❌')
|
| 75 |
time.sleep(1) # 延迟1秒后继续运行代码
|
| 76 |
return None, None
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
# 网页前端显示
|
| 81 |
-
st.set_page_config(page_title="EthPen - 批量 Mint
|
| 82 |
|
| 83 |
# 网页标题
|
| 84 |
-
st.subheader(r'🪙 :rainbow[EthPen - 批量 Mint
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
st.markdown('
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
''
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
approved_use = False
|
| 112 |
-
|
| 113 |
-
if approved_use:
|
| 114 |
-
|
| 115 |
-
st.markdown('## 批量题写 $pols 代币')
|
| 116 |
-
|
| 117 |
-
# 这里配置 Ethereum PRC URL,如果你没有,请到 infura.io 或者 alchemy.com 申请一个免费的 API
|
| 118 |
-
token_eth_prc_url = st.text_input(
|
| 119 |
-
f'**Polygon PRC 链接**:选填,你可以去 [infura.io](https://app.infura.io/) 或者 [alchemy.com](https://alchemy.com/) 免费申请一个',
|
| 120 |
-
f'https://polygon-mainnet.infura.io/v3/ae62dc706386486189a47641e73b43c0')
|
| 121 |
-
w3 = Web3(Web3.HTTPProvider(f'{token_eth_prc_url}'))
|
| 122 |
-
|
| 123 |
-
# 初始化当前账户索引为 0
|
| 124 |
-
current_account_index = 0
|
| 125 |
-
# 收集和显示所有交易的结果
|
| 126 |
-
transaction_results = []
|
| 127 |
-
# 创建账户列表
|
| 128 |
-
accounts = []
|
| 129 |
-
# 使用字典来跟踪每个地址的nonce
|
| 130 |
-
nonces = {}
|
| 131 |
-
|
| 132 |
-
account_address = st.text_input('填写你的 **ETH 地址**:')
|
| 133 |
-
private_key = st.text_input('填写你的 **ETH 地址对应的私钥**:', type="password")
|
| 134 |
-
if account_address and private_key: # 如果地址和私钥有内容
|
| 135 |
-
if is_valid_eth_address(account_address) and is_valid_eth_private_key(private_key): # 验证地址和私钥
|
| 136 |
-
current_nonce = w3.eth.get_transaction_count(account_address) # 获取地址的 nonce
|
| 137 |
-
nonces[account_address] = current_nonce # 记录地址的 nonce
|
| 138 |
-
accounts.append((account_address.strip(), private_key.strip())) # 保存地址和私钥还有 nonce
|
| 139 |
-
else:
|
| 140 |
-
st.error("地址或私钥无效,请检查!")
|
| 141 |
-
st.stop()
|
| 142 |
-
|
| 143 |
-
# 配置铭文文本
|
| 144 |
-
input_data = st.text_input('填写需要题写代币铭文文本', 'data:,{"p":"prc-20","op":"mint","tick":"pols","amt":"100000000"}')
|
| 145 |
-
token_amount = st.number_input('填写需要题写代币铭文数量(张)', min_value=1, value=100, step=1)
|
| 146 |
-
# 判断铭文文本里是否包含空格、换行符,而且所有的字母都必须为小写。
|
| 147 |
-
if not validate_input(f'{input_data}'):
|
| 148 |
-
st.warning("**请注意**:通常代币铭文文本里不能包含空格、换行符,而且所有的字母都必须为小写。")
|
| 149 |
-
|
| 150 |
-
sleep_05s = st.toggle('每次完成交易后暂��� 0.5 秒')
|
| 151 |
-
# 每次交易成功后暂停 3 秒
|
| 152 |
-
if sleep_05s:
|
| 153 |
-
sleep_05s = True
|
| 154 |
else:
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
# 更新当前账户索引,确保索引始终在账户列表的范围内
|
| 170 |
-
current_account_index = (current_account_index + 1) % len(accounts)
|
| 171 |
-
# 暂停 3 秒
|
| 172 |
-
if sleep_05s:
|
| 173 |
-
time.sleep(0.5) # 暂停三秒
|
| 174 |
-
st.toast(f'所有任务已经完成。', icon='🎉')
|
| 175 |
-
# 庆祝动画
|
| 176 |
-
st.balloons()
|
| 177 |
-
# 显示所有交易的结果
|
| 178 |
-
st.code('\n'.join(transaction_results))
|
| 179 |
else:
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# 发送签名后的交易并获取交易哈希
|
| 68 |
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
| 69 |
# 打印结果信息
|
| 70 |
+
st.toast(f'{the_id},上链了!', icon='✅')
|
| 71 |
# 返回铭文还有交易哈希
|
| 72 |
return input_data, tx_hash.hex()
|
| 73 |
except Exception as e:
|
| 74 |
+
st.toast(f'{the_id},不用管!', icon='❌')
|
| 75 |
time.sleep(1) # 延迟1秒后继续运行代码
|
| 76 |
return None, None
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
# 网页前端显示
|
| 81 |
+
st.set_page_config(page_title="EthPen - 批量 Mint Polygon inscription", page_icon="🪙", layout='centered', initial_sidebar_state='auto')
|
| 82 |
|
| 83 |
# 网页标题
|
| 84 |
+
st.subheader(r'🪙 :rainbow[EthPen - 批量 Mint Polygon inscription]', anchor=False, divider='rainbow')
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
st.markdown('## 批量题写 Polygon inscription 代币')
|
| 88 |
+
|
| 89 |
+
# 这里配置 Ethereum PRC URL,如果你没有,请到 infura.io 或者 alchemy.com 申请一个免费的 API
|
| 90 |
+
token_eth_prc_url = st.text_input(
|
| 91 |
+
f'**Polygon PRC 链接**:选填,你可以去 [infura.io](https://app.infura.io/) 或者 [alchemy.com](https://alchemy.com/) 免费申请一个',
|
| 92 |
+
f'https://polygon-mainnet.infura.io/v3/ae62dc706386486189a47641e73b43c0')
|
| 93 |
+
w3 = Web3(Web3.HTTPProvider(f'{token_eth_prc_url}'))
|
| 94 |
+
|
| 95 |
+
# 初始化当前账户索引为 0
|
| 96 |
+
current_account_index = 0
|
| 97 |
+
# 收集和显示所有交易的结果
|
| 98 |
+
transaction_results = []
|
| 99 |
+
# 创建账户列表
|
| 100 |
+
accounts = []
|
| 101 |
+
# 使用字典来跟踪每个地址的nonce
|
| 102 |
+
nonces = {}
|
| 103 |
+
|
| 104 |
+
account_address = st.text_input('填写你的 **ETH 地址**:')
|
| 105 |
+
private_key = st.text_input('填写你的 **ETH 地址对应的私钥**:', type="password")
|
| 106 |
+
if account_address and private_key: # 如果地址和私钥有内容
|
| 107 |
+
if is_valid_eth_address(account_address) and is_valid_eth_private_key(private_key): # 验证地址和私钥
|
| 108 |
+
current_nonce = w3.eth.get_transaction_count(account_address) # 获取地址的 nonce
|
| 109 |
+
nonces[account_address] = current_nonce # 记录地址的 nonce
|
| 110 |
+
accounts.append((account_address.strip(), private_key.strip())) # 保存地址和私钥还有 nonce
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
else:
|
| 112 |
+
st.error("地址或私钥无效,请检查!")
|
| 113 |
+
st.stop()
|
| 114 |
+
|
| 115 |
+
# 配置铭文文本
|
| 116 |
+
input_data = st.text_input('填写需要题写代币铭文文本', 'data:,{"a":"NextInscription","p":"oprc-20","op":"mint","tick":"anteater","amt":"100000000"}')
|
| 117 |
+
token_amount = st.number_input('填写需要题写代币铭文数量(张)', min_value=1, value=100, step=1)
|
| 118 |
+
# 判断铭文文本里是否包含空格、换行符,而且所有的字母都必须为小写。
|
| 119 |
+
if not validate_input(f'{input_data}'):
|
| 120 |
+
st.warning("**请注意**:通常代币铭文文本里不能包含空格、换行符,而且所有的字母都必须为小写。")
|
| 121 |
+
|
| 122 |
+
sleep_05s = st.toggle('每次完成交易后暂停 0.5 秒')
|
| 123 |
+
# 每次交易成功后暂停 3 秒
|
| 124 |
+
if sleep_05s:
|
| 125 |
+
sleep_05s = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
else:
|
| 127 |
+
sleep_05s = False
|
| 128 |
+
|
| 129 |
+
# 点击发送交易开始
|
| 130 |
+
if st.button(f'开始**发送交易**'):
|
| 131 |
+
st.toast(f'开始任务,需要题写的铭文总量为:{token_amount}', icon='😎')
|
| 132 |
+
# 对代币铭文 id 进行循环
|
| 133 |
+
for the_id in range(token_amount):
|
| 134 |
+
# 使用当前账户发送交易,获取当前账户的 nonce
|
| 135 |
+
address, key = accounts[current_account_index]
|
| 136 |
+
# 使用 current_nonce 发送交易
|
| 137 |
+
data, tx_hash = send_transaction(w3, address, key, 137, input_data, the_id)
|
| 138 |
+
# 记录最后输出的结果
|
| 139 |
+
transaction_results.append(f"Transaction Hash: https://polygonscan.com/tx/{tx_hash}")
|
| 140 |
+
# 交易成功后,手动增加 nonce 值
|
| 141 |
+
# 更新当前账户索引,确保索引始终在账户列表的范围内
|
| 142 |
+
current_account_index = (current_account_index + 1) % len(accounts)
|
| 143 |
+
# 暂停 3 秒
|
| 144 |
+
if sleep_05s:
|
| 145 |
+
time.sleep(0.5) # 暂停三秒
|
| 146 |
+
st.toast(f'所有任务已经完成。', icon='🎉')
|
| 147 |
+
# 庆祝动画
|
| 148 |
+
st.balloons()
|
| 149 |
+
# 显示所有交易的结果
|
| 150 |
+
st.code('\n'.join(transaction_results))
|
| 151 |
+
|