DragandDropGroup commited on
Commit
f78ee01
·
verified ·
1 Parent(s): e63399e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +98 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,100 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from web3 import Web3
3
+ 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.")
11
+
12
+ 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
+ {
20
+ "inputs": [
21
+ {
22
+ "internalType": "string",
23
+ "name": "ipfsHash",
24
+ "type": "string"
25
+ }
26
+ ],
27
+ "name": "storeHash",
28
+ "outputs": [],
29
+ "stateMutability": "nonpayable",
30
+ "type": "function"
31
+ },
32
+ {
33
+ "inputs": [],
34
+ "name": "getHashes",
35
+ "outputs": [
36
+ {
37
+ "internalType": "string[]",
38
+ "name": "",
39
+ "type": "string[]"
40
+ }
41
+ ],
42
+ "stateMutability": "view",
43
+ "type": "function"
44
+ },
45
+ {
46
+ "anonymous": false,
47
+ "inputs": [
48
+ {
49
+ "indexed": false,
50
+ "internalType": "string",
51
+ "name": "ipfsHash",
52
+ "type": "string"
53
+ }
54
+ ],
55
+ "name": "Store",
56
+ "type": "event"
57
+ }
58
+ ]
59
+ """)
60
+
61
+
62
+ contract_bytecode = "608060405234801561001057600080fd5b506101a8806100206000396000f3fe6080604052600436106100295760003560e01c806360fe47b11461002e5780636d4ce63c1461004c575b600080fd5b61003661006a565b6040516100439190610111565b60405180910390f35b610054610090565b6040516100619190610111565b60405180910390f35b60008054905090565b600055565b60005481565b6000805490509056fea2646970667358221220b89e9443c7c22a3a69fcb9635b2a2d226781eb1d6c78b8eb80ac520cfe1dc4a364736f6c63430008040033"
63
+
64
+ # Deploy contract when button is clicked
65
+ if st.button("Deploy Contract"):
66
+ if not all([wallet_address, private_key, infura_url]):
67
+ st.warning("Please fill in all fields.")
68
+ else:
69
+ try:
70
+ w3 = Web3(Web3.HTTPProvider(infura_url))
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,
87
+ 'gasPrice': w3.to_wei('10', 'gwei')
88
+ })
89
+
90
+ # Sign and send transaction
91
+ signed_tx = w3.eth.account.sign_transaction(tx, private_key)
92
+ tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
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}")