smejak commited on
Commit
fda2244
1 Parent(s): 5fec2b3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ocean_lib.config import Config
2
+ from ocean_lib.models.btoken import BToken #BToken is ERC20
3
+ from ocean_lib.ocean.ocean import Ocean
4
+ from ocean_lib.web3_internal.wallet import Wallet
5
+ from ocean_lib.web3_internal.currency import from_wei # wei is the smallest denomination of ether e.g. like cents
6
+ # from ocean_lib.web3_internal.currency import pretty_ether_and_wei
7
+ import streamlit as st
8
+ from wallet_connect import connect
9
+
10
+ d = {
11
+ 'network' : 'https://rinkeby.infura.io/v3/d163c48816434b0bbb3ac3925d6c6c80',
12
+ 'BLOCK_CONFIRMATIONS': 0,
13
+ 'metadataCacheUri' : 'https://aquarius.oceanprotocol.com',
14
+ 'providerUri' : 'https://provider.rinkeby.oceanprotocol.com',
15
+ 'PROVIDER_ADDRESS': '0x00bd138abd70e2f00903268f3db08f2d25677c9e',
16
+ 'downloads.path': 'consume-downloads',
17
+ }
18
+
19
+ ocean = Ocean(d)
20
+
21
+ def wallet():
22
+
23
+ address = connect("wallet")
24
+
25
+ if address != "not":
26
+
27
+ OCEAN_token = BToken(ocean.web3, ocean.OCEAN_address)
28
+
29
+ eth_balance = from_wei(ocean.web3.eth.get_balance(address))
30
+ ocean_balance = from_wei(OCEAN_token.balanceOf(address))
31
+
32
+ st.write(f'Address: {address}')
33
+ st.write(f'ETH Balance: {eth_balance}')
34
+ st.write(f'OCEAN Balance: {ocean_balance}')
35
+
36
+ st.header("Web3 Wallet")
37
+ text = """
38
+ This demo shows the balance of tokens in your Web3 wallet.
39
+ If you do not have a Web3 wallet, see instructions on setting up a wallet in the links below.
40
+ Initially, your wallet should have no ETH and OCEAN tokens in it.
41
+ You can then request ETH and OCEAN test tokens by entering your public address into faucets
42
+ (follow the links at the bottom of the page).
43
+ Then wait about 15 seconds and re-run the app for the same private key.
44
+ This demo uses the Ocean Protocol Python library in the backend.
45
+ For more information on the advantages of combinining Ocean and HuggingFace,
46
+ check out the blog post link below.
47
+
48
+ Setup MetaMask: [https://www.oceanacademy.io/ocean101/chapter-8](https://www.oceanacademy.io/ocean101/chapter-8)
49
+
50
+ Get Rinkeby ETH: [https://faucet.rinkeby.io/](https://faucet.rinkeby.io/)
51
+
52
+ Get Test Ocean: [https://faucet.rinkeby.oceanprotocol.com/](https://faucet.rinkeby.oceanprotocol.com/)
53
+ """
54
+ st.write(text)
55
+
56
+ wallet()