Spaces:
Runtime error
Runtime error
import gradio as gr | |
from ocean_lib.config import Config | |
from ocean_lib.models.btoken import BToken #BToken is ERC20 | |
from ocean_lib.ocean.ocean import Ocean | |
from ocean_lib.web3_internal.wallet import Wallet | |
from ocean_lib.web3_internal.currency import from_wei # wei is the smallest denomination of ether e.g. like cents | |
config = Config('config.ini') | |
ocean = Ocean(config) | |
def wallet(private_key): | |
wallet = Wallet(ocean.web3, private_key, transaction_timeout=20, block_confirmations=config.block_confirmations) | |
address = wallet.address | |
OCEAN_token = BToken(ocean.web3, ocean.OCEAN_address) | |
eth_balance = from_wei(ocean.web3.eth.get_balance(wallet.address)) | |
ocean_balance = from_wei(OCEAN_token.balanceOf(wallet.address)) | |
return address, eth_balance, ocean_balance | |
description = ( | |
"This demo calculate the number of tokens in your wallet on the Rinkeby test network using the Ocean Python library. \n" | |
"You can export your private key from your metamask wallet. We highly recommend doing this with a wallet that has no real tokens in it (only Rinkeby tokens)." | |
"For more info on private keys, see [this](https://github.com/oceanprotocol/ocean.py/blob/main/READMEs/wallets.md) from the ocean.py documentation" | |
) | |
article = ( | |
"<p style='text-align: center'>" | |
"<a href='https://oceanprotocol.com/' target='_blank'>Ocean Protocol</a> | " | |
"<a href='https://github.com/oceanprotocol/ocean.py' target='_blank'>Ocean Python Library</a> | " | |
"<a href='https://www.algovera.ai' target='_blank'>Algovera</a>" | |
"</p>" | |
) | |
interface = gr.Interface( | |
wallet, | |
"text", | |
[ | |
gr.outputs.Textbox(label="Public Key"), | |
gr.outputs.Textbox(label="ETH balance"), | |
gr.outputs.Textbox(label="OCEAN balance"), | |
], | |
title="Ocean Token Calculator", | |
description=description, | |
article=article, | |
theme="huggingface", | |
) | |
interface.launch() |