-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
73 lines (54 loc) · 2.15 KB
/
app.py
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
import os
import json
from web3 import Web3
from pathlib import Path
from dotenv import load_dotenv
import streamlit as st
# load variables from .env
load_dotenv()
# setup we3 instance
w3 = Web3(Web3.HTTPProvider(os.getenv("WEB3_PROVIDER_URI")))
@st.cache(allow_output_mutation=True)
def load_contract():
with open(Path('./contracts/compiled/artwork_abi.json')) as f:
artwork_abi = json.load(f)
contract_address = os.getenv("SMART_CONTRACT_ADDRESS")
contract = w3.eth.contract(
address=contract_address,
abi=artwork_abi
)
return contract
# load contract
contract = load_contract()
# streamlit frontend
# The user is be able to select an account for the contract owner from a list of accounts.
# And, the user is be able to enter a URI that links to a piece of digital artwork
st.title("Register New Artwork")
accounts = w3.eth.accounts
address = st.selectbox("Select Artwork Owner", options=accounts)
artwork_uri = st.text_input("The URI to the artwork")
if st.button("Register Artwork"):
tx_hash = contract.functions.registerArtwork(address, artwork_uri).transact({
"from": address,
"gas": 1000000
})
receipt = w3.eth.waitForTransactionReceipt(tx_hash)
st.write("Transaction receipt mined:")
st.write(dict(receipt))
st.markdown("---")
################################################################################
# Display a Token
################################################################################
st.markdown("## Display an Art Token")
selected_address = st.selectbox("Select Account", options=accounts)
tokens = contract.functions.balanceOf(selected_address).call()
st.write(f"This address owns {tokens} tokens")
token_id = st.selectbox("Artwork Tokens", list(range(tokens)))
if st.button("Display"):
# Use the contract's `ownerOf` function to get the art token owner
owner = contract.functions.ownerOf(token_id).call()
st.write(f"The token is registered to {owner}")
# Use the contract's `tokenURI` function to get the art token's URI
token_uri = contract.functions.tokenURI(token_id).call()
st.write(f"The tokenURI is {token_uri}")
st.image(token_uri)