Spaces:
Runtime error
Runtime error
Commit
·
e82d1af
1
Parent(s):
1db73ac
add eth and ocean balance as outputs
Browse files
app.py
CHANGED
|
@@ -1,15 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ocean_lib.config import Config
|
|
|
|
| 3 |
from ocean_lib.ocean.ocean import Ocean
|
| 4 |
from ocean_lib.web3_internal.wallet import Wallet
|
| 5 |
-
import
|
| 6 |
|
| 7 |
config = Config('config.ini')
|
| 8 |
ocean = Ocean(config)
|
| 9 |
|
| 10 |
-
def
|
| 11 |
wallet = Wallet(ocean.web3, private_key, transaction_timeout=20, block_confirmations=config.block_confirmations)
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
description = (
|
| 15 |
"This demo calculate the number of tokens in your wallet on the Rinkeby test network using the Ocean Python library. "
|
|
@@ -25,11 +32,14 @@ article = (
|
|
| 25 |
"</p>"
|
| 26 |
)
|
| 27 |
|
|
|
|
| 28 |
interface = gr.Interface(
|
| 29 |
-
|
| 30 |
"text",
|
| 31 |
[
|
| 32 |
-
gr.outputs.Textbox(label="Public Key")
|
|
|
|
|
|
|
| 33 |
],
|
| 34 |
title="Ocean Token Calculator",
|
| 35 |
description=description,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ocean_lib.config import Config
|
| 3 |
+
from ocean_lib.models.btoken import BToken #BToken is ERC20
|
| 4 |
from ocean_lib.ocean.ocean import Ocean
|
| 5 |
from ocean_lib.web3_internal.wallet import Wallet
|
| 6 |
+
from ocean_lib.web3_internal.currency import from_wei # wei is the smallest denomination of ether e.g. like cents
|
| 7 |
|
| 8 |
config = Config('config.ini')
|
| 9 |
ocean = Ocean(config)
|
| 10 |
|
| 11 |
+
def wallet(private_key):
|
| 12 |
wallet = Wallet(ocean.web3, private_key, transaction_timeout=20, block_confirmations=config.block_confirmations)
|
| 13 |
+
address = wallet.address
|
| 14 |
+
OCEAN_token = BToken(ocean.web3, ocean.OCEAN_address)
|
| 15 |
+
|
| 16 |
+
eth_balance = from_wei(ocean.web3.eth.get_balance(wallet.address))
|
| 17 |
+
ocean_balance = from_wei(OCEAN_token.balanceOf(wallet.address))
|
| 18 |
+
|
| 19 |
+
return address, eth_balance, ocean_balance
|
| 20 |
|
| 21 |
description = (
|
| 22 |
"This demo calculate the number of tokens in your wallet on the Rinkeby test network using the Ocean Python library. "
|
|
|
|
| 32 |
"</p>"
|
| 33 |
)
|
| 34 |
|
| 35 |
+
|
| 36 |
interface = gr.Interface(
|
| 37 |
+
wallet,
|
| 38 |
"text",
|
| 39 |
[
|
| 40 |
+
gr.outputs.Textbox(label="Public Key"),
|
| 41 |
+
gr.outputs.Textbox(label="ETH balance"),
|
| 42 |
+
gr.outputs.Textbox(label="ETOCEANH balance"),
|
| 43 |
],
|
| 44 |
title="Ocean Token Calculator",
|
| 45 |
description=description,
|