Spaces:
Sleeping
Sleeping
Commit
·
9ab57a6
1
Parent(s):
f1fd83c
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,26 +47,30 @@ def sha256(input_string):
|
|
| 47 |
|
| 48 |
# 发送自己到自己 0ETH 的交易
|
| 49 |
def send_transaction(w3, account_address, private_key, chain_id, gas_price, input_data, current_nonce):
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
# 网页前端显示
|
|
|
|
| 47 |
|
| 48 |
# 发送自己到自己 0ETH 的交易
|
| 49 |
def send_transaction(w3, account_address, private_key, chain_id, gas_price, input_data, current_nonce):
|
| 50 |
+
try:
|
| 51 |
+
# 设置交易的相关信息
|
| 52 |
+
tx = {
|
| 53 |
+
'chainId': chain_id, # 网络 ID
|
| 54 |
+
'gas': 25000, # 如果交易 gas 过低,可适当调高
|
| 55 |
+
'gasPrice': gas_price, # gas 的价格
|
| 56 |
+
'nonce': current_nonce,
|
| 57 |
+
'to': account_address, # 接收地址为自己
|
| 58 |
+
'value': 0, # 金额为 0ETH
|
| 59 |
+
'data': text_to_hex(input_data), # 铭文内容
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
# 用私钥签名这个交易
|
| 63 |
+
signed_tx = w3.eth.account.sign_transaction(tx, private_key)
|
| 64 |
+
# 发送签名后的交易并获取交易哈希
|
| 65 |
+
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
|
| 66 |
+
# 打印结果信息
|
| 67 |
+
st.toast(f'{tx_hash.hex()}', icon='✅')
|
| 68 |
+
# 返回铭文还有交易哈希
|
| 69 |
+
return input_data, tx_hash.hex()
|
| 70 |
+
except Exception as e:
|
| 71 |
+
st.toast(f'Error: {str(e)}', icon='❌')
|
| 72 |
+
time.sleep(1) # 延迟1秒后继续运行代码
|
| 73 |
+
return None, None
|
| 74 |
|
| 75 |
|
| 76 |
# 网页前端显示
|