File size: 6,070 Bytes
b16af8b
f78ee01
 
 
 
b16af8b
f78ee01
 
 
 
 
 
 
 
e85707b
 
 
f78ee01
 
e85707b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f78ee01
 
 
e85707b
f78ee01
 
 
 
 
 
 
 
 
 
 
8d32176
f78ee01
 
 
 
 
 
8d32176
f78ee01
 
 
 
 
 
 
 
 
 
 
 
8d32176
f78ee01
8d32176
f78ee01
8d32176
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import streamlit as st
from web3 import Web3
import json
import os
os.environ["STREAMLIT_TELEMETRY_ENABLED"] = "0"

# Streamlit UI
st.title("Smart Contract Deployer")
st.write("Deploy a smart contract using your Ethereum wallet.")

wallet_address = st.text_input("Enter your wallet address:")
private_key = st.text_input("Enter your private key:", type="password")
infura_url = st.text_input("Enter your Infura URL:")

#ABI for IPFSStorage
import json

contract_abi = json.loads("""
[
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "string",
        "name": "ipfsHash",
        "type": "string"
      }
    ],
    "name": "Store",
    "type": "event"
  },
  {
    "inputs": [],
    "name": "getHashes",
    "outputs": [
      {
        "internalType": "string[]",
        "name": "",
        "type": "string[]"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "ipfsHash",
        "type": "string"
      }
    ],
    "name": "storeHash",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]
""")

contract_bytecode = "0x608060405234801561001057600080fd5b50610655806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634245d48e1461003b57806371dc61cb14610059575b600080fd5b610043610075565b604051610050919061040b565b60405180910390f35b610073600480360381019061006e91906102cf565b61014e565b005b60606000805480602002602001604051908101604052809291908181526020016000905b828210156101455783829060005260206000200180546100b89061054d565b80601f01602080910402602001604051908101604052809291908181526020018280546100e49061054d565b80156101315780601f1061010657610100808354040283529160200191610131565b820191906000526020600020905b81548152906001019060200180831161011457829003601f168201915b505050505081526020019060010190610099565b50505050905090565b6000819080600181540180825580915050600190039060005260206000200160009091909190915090805190602001906101899291906101c4565b507f4f9c5253c28d756a479eda13b65899a3ad16e0b50d4100ef22348b747b709216816040516101b9919061042d565b60405180910390a150565b8280546101d09061054d565b90600052602060002090601f0160209004810192826101f25760008555610239565b82601f1061020b57805160ff1916838001178555610239565b82800160010185558215610239579182015b8281111561023857825182559160200191906001019061021d565b5b509050610246919061024a565b5090565b5b8082111561026357600081600090555060010161024b565b5090565b600061027a61027584610474565b61044f565b90508281526020810184848401111561029257600080fd5b61029d84828561050b565b509392505050565b600082601f8301126102b657600080fd5b81356102c6848260208601610267565b91505092915050565b6000602082840312156102e157600080fd5b600082013567ffffffffffffffff8111156102fb57600080fd5b610307848285016102a5565b91505092915050565b600061031c8383610399565b905092915050565b600061032f826104b5565b61033981856104d8565b93508360208202850161034b856104a5565b8060005b8581101561038757848403895281516103688582610310565b9450610373836104cb565b925060208a0199505060018101905061034f565b50829750879550505050505092915050565b60006103a4826104c0565b6103ae81856104e9565b93506103be81856020860161051a565b6103c78161060e565b840191505092915050565b60006103dd826104c0565b6103e781856104fa565b93506103f781856020860161051a565b6104008161060e565b840191505092915050565b600060208201905081810360008301526104258184610324565b905092915050565b6000602082019050818103600083015261044781846103d2565b905092915050565b600061045961046a565b9050610465828261057f565b919050565b6000604051905090565b600067ffffffffffffffff82111561048f5761048e6105df565b5b6104988261060e565b9050602081019050919050565b6000819050602082019050919050565b600081519050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600082825260208201905092915050565b600082825260208201905092915050565b82818337600083830152505050565b60005b8381101561053857808201518184015260208101905061051d565b83811115610547576000848401525b50505050565b6000600282049050600182168061056557607f821691505b60208210811415610579576105786105b0565b5b50919050565b6105888261060e565b810181811067ffffffffffffffff821117156105a7576105a66105df565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000601f19601f830116905091905056fea264697066735822122048abd857324db30c9ef1d5b905b229d966a49e007230d72ee76cf68a7716abbe64736f6c63430008020033"

# Deploy contract when button is clicked
if st.button("Deploy Contract"):
    if not all([wallet_address, private_key, infura_url]):
        st.warning("Please fill in all fields.")
    else:
        try:
            w3 = Web3(Web3.HTTPProvider(infura_url))
            if not w3.is_connected():
                st.error("Could not connect to Ethereum network. Check your Infura URL.")
            else:
                st.success("Connected to Sepolia!")

                contract = w3.eth.contract(abi=contract_abi, bytecode=contract_bytecode)
                nonce = w3.eth.get_transaction_count(wallet_address)

                # Build transaction
                tx = contract.constructor().build_transaction({
                    'chainId': 11155111,  # Sepolia chain ID
                    'from': wallet_address,
                    'nonce': nonce,
                    'gas': 3000000,
                    'gasPrice': w3.to_wei('10', 'gwei')
                })

                # Sign and send transaction
                signed_tx = w3.eth.account.sign_transaction(tx, private_key)
                tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)

                st.write("Deploying contract... Transaction hash:", tx_hash.hex())

                # Wait for receipt
                tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
                st.success(f"✅ Contract deployed successfully at: `{tx_receipt.contractAddress}`")
        except Exception as e:
            st.error(f"Error deploying contract: {e}")