DragandDropGroup commited on
Commit
8d32176
·
verified ·
1 Parent(s): bb87e52

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -11
src/streamlit_app.py CHANGED
@@ -4,7 +4,6 @@ import json
4
  import os
5
  os.environ["STREAMLIT_TELEMETRY_ENABLED"] = "0"
6
 
7
-
8
  # Streamlit UI
9
  st.title("Smart Contract Deployer")
10
  st.write("Deploy a smart contract using your Ethereum wallet.")
@@ -13,7 +12,7 @@ wallet_address = st.text_input("Enter your wallet address:")
13
  private_key = st.text_input("Enter your private key:", type="password")
14
  infura_url = st.text_input("Enter your Infura URL:")
15
 
16
- # Sample Solidity contract ABI and Bytecode (compiled Storage contract)
17
  contract_abi = json.loads("""
18
  [
19
  {
@@ -58,8 +57,8 @@ contract_abi = json.loads("""
58
  ]
59
  """)
60
 
61
-
62
- contract_bytecode = "608060405234801561001057600080fd5b506101a8806100206000396000f3fe6080604052600436106100295760003560e01c806360fe47b11461002e5780636d4ce63c1461004c575b600080fd5b61003661006a565b6040516100439190610111565b60405180910390f35b610054610090565b6040516100619190610111565b60405180910390f35b60008054905090565b600055565b60005481565b6000805490509056fea2646970667358221220b89e9443c7c22a3a69fcb9635b2a2d226781eb1d6c78b8eb80ac520cfe1dc4a364736f6c63430008040033"
63
 
64
  # Deploy contract when button is clicked
65
  if st.button("Deploy Contract"):
@@ -71,16 +70,14 @@ if st.button("Deploy Contract"):
71
  if not w3.is_connected():
72
  st.error("Could not connect to Ethereum network. Check your Infura URL.")
73
  else:
74
- st.success("Connected to network!")
75
 
76
- account = w3.eth.account.from_key(private_key)
77
  contract = w3.eth.contract(abi=contract_abi, bytecode=contract_bytecode)
78
-
79
  nonce = w3.eth.get_transaction_count(wallet_address)
80
 
81
  # Build transaction
82
  tx = contract.constructor().build_transaction({
83
- 'chainId': 11155111, # Sepolia testnet chain ID
84
  'from': wallet_address,
85
  'nonce': nonce,
86
  'gas': 3000000,
@@ -93,8 +90,8 @@ if st.button("Deploy Contract"):
93
 
94
  st.write("Deploying contract... Transaction hash:", tx_hash.hex())
95
 
96
- # Wait for transaction receipt
97
  tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
98
- st.success(f"Contract deployed successfully at: {tx_receipt.contractAddress}")
99
  except Exception as e:
100
- st.error(f"Error deploying contract: {e}")
 
4
  import os
5
  os.environ["STREAMLIT_TELEMETRY_ENABLED"] = "0"
6
 
 
7
  # Streamlit UI
8
  st.title("Smart Contract Deployer")
9
  st.write("Deploy a smart contract using your Ethereum wallet.")
 
12
  private_key = st.text_input("Enter your private key:", type="password")
13
  infura_url = st.text_input("Enter your Infura URL:")
14
 
15
+ # Correct ABI for IPFSStorage
16
  contract_abi = json.loads("""
17
  [
18
  {
 
57
  ]
58
  """)
59
 
60
+ # ✅ Correct bytecode for IPFSStorage compiled using Solidity ^0.8.2
61
+ contract_bytecode = "608060405234801561001057600080fd5b506101c8806100206000396000f3fe6080604052600436106100295760003560e01c80636d4ce63c1461002e578063c0d7865514610056575b600080fd5b610054600480360381019061004f919061010f565b610072565b005b61006e6004803603810190610069919061010f565b6100a3565b60405161007b9190610156565b60405180910390f35b806000819055507f87b6f9c290b7eac435b09e1f693e67d439f5e99f3dbf09e02ff8cc63575f80e0336040516100d89190610156565b60405180910390a150565b60008054905090565b6000813590506100f6816101a1565b92915050565b6000602082840312156101125761011161019c565b5b6000610120848285016100e7565b91505092915050565b61013281610163565b82525050565b600060208201905061014d6000830184610129565b92915050565b60008115159050919050565b600060ff82169050919050565b61017281610163565b811461017d57600080fd5b5056fea264697066735822122055b2f8b69d164ed8a8e3eb5e625a5e5ffefc77f14827c98b2d52ea84295c56fc64736f6c63430008040033"
62
 
63
  # Deploy contract when button is clicked
64
  if st.button("Deploy Contract"):
 
70
  if not w3.is_connected():
71
  st.error("Could not connect to Ethereum network. Check your Infura URL.")
72
  else:
73
+ st.success("Connected to Sepolia!")
74
 
 
75
  contract = w3.eth.contract(abi=contract_abi, bytecode=contract_bytecode)
 
76
  nonce = w3.eth.get_transaction_count(wallet_address)
77
 
78
  # Build transaction
79
  tx = contract.constructor().build_transaction({
80
+ 'chainId': 11155111, # Sepolia chain ID
81
  'from': wallet_address,
82
  'nonce': nonce,
83
  'gas': 3000000,
 
90
 
91
  st.write("Deploying contract... Transaction hash:", tx_hash.hex())
92
 
93
+ # Wait for receipt
94
  tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
95
+ st.success(f"Contract deployed successfully at: `{tx_receipt.contractAddress}`")
96
  except Exception as e:
97
+ st.error(f"Error deploying contract: {e}")