Ethscriptions commited on
Commit
2e9b9aa
·
1 Parent(s): ea0e23c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -47,11 +47,10 @@ 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
  tx = {
53
  'chainId': chain_id, # 网络 ID
54
- 'gas': 25000, # 如果交易 gas 过低,可适当调高
55
  'gasPrice': gas_price, # gas 的价格
56
  'nonce': current_nonce,
57
  'to': account_address, # 接收地址为自己
@@ -59,6 +58,9 @@ def send_transaction(w3, account_address, private_key, chain_id, gas_price, inpu
59
  'data': text_to_hex(input_data), # 铭文内容
60
  }
61
 
 
 
 
62
  # 用私钥签名这个交易
63
  signed_tx = w3.eth.account.sign_transaction(tx, private_key)
64
  # 发送签名后的交易并获取交易哈希
@@ -173,4 +175,5 @@ if approved_use:
173
  # 显示所有交易的结果
174
  st.code('\n'.join(transaction_results))
175
  else:
176
- st.error('# 阅读并打勾 ✅ 后方可使用。')
 
 
47
 
48
  # 发送自己到自己 0ETH 的交易
49
  def send_transaction(w3, account_address, private_key, chain_id, gas_price, input_data, current_nonce):
 
50
  # 设置交易的相关信息
51
  tx = {
52
  'chainId': chain_id, # 网络 ID
53
+ # 'gas': 25000, # 原始的固定 gas
54
  'gasPrice': gas_price, # gas 的价格
55
  'nonce': current_nonce,
56
  'to': account_address, # 接收地址为自己
 
58
  'data': text_to_hex(input_data), # 铭文内容
59
  }
60
 
61
+ # 估算交易所需的 gas
62
+ tx['gas'] = w3.eth.estimate_gas(tx)
63
+
64
  # 用私钥签名这个交易
65
  signed_tx = w3.eth.account.sign_transaction(tx, private_key)
66
  # 发送签名后的交易并获取交易哈希
 
175
  # 显示所有交易的结果
176
  st.code('\n'.join(transaction_results))
177
  else:
178
+ st.error('# 阅读并打勾 ✅ 后方可使用。')
179
+