Getting contract details from address

I’m trying to retrieve contract details (Token name, symbol) from a contract addresses. For example in the Internal Transactions of this transaction, you see the contract address is replaced by the names: Jewel LP Token, Venom LP Token. I can’t seem to find any API calls where I can pass a contract address and get details of that address returned.

How is Harmony’s block explorer looking up those names? Is that part of an internal dictionary or is there a public repository or API where I can match contract addresses to details?

I need to programmatically match addresses, so HTML pages like this one aren’t ideal as writing a scraper is not so reliable

You will have to call the contract functions name() , symbol() etc which are a part of the ERC20 standard so every token should have these.

You can use a Web3 implementation to achieve this.

I have an example below in Python but it is the same in any language as web3 is a standard and not specific to any language.

from web3 import Web3
import sys

wss_url = "wss://ws.s0.t.hmny.io"
w3 = Web3(Web3.WebsocketProvider(wss_url))
is_connected = w3.isConnected()

if not is_connected:
    print("Not Connected")
    sys.exit()
print(f"Connected :: {is_connected}")

contracts = (
    "0x72Cb10C6bfA5624dD07Ef608027E366bd690048F", # JEWEL
    "0x01A4b054110d57069c1658AFBC46730529A3E326", # OPENSWAP
)

# Simple version of ERC20 contract.
# Add any other requirements from the contract or save the ERC20 Abi to Json and read from it.
# Example here: https://ethereumdev.io/abi-for-erc20-contract-on-ethereum/
abi = [

    {
        "inputs": [],
        "name": "decimals",
        "outputs": [{"internalType": "uint8", "name": "", "type": "uint8"}],
        "stateMutability": "view",
        "type": "function",
        "constant": True,
    },
    {
        "inputs": [],
        "name": "symbol",
        "outputs": [{"internalType": "string", "name": "", "type": "string"}],
        "stateMutability": "view",
        "type": "function",
        "constant": True,
    },
    {
        "inputs": [],
        "name": "totalSupply",
        "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
        "stateMutability": "view",
        "type": "function",
        "constant": True,
    },
    {
        "inputs": [],
        "name": "name",
        "outputs": [{"internalType": "string", "name": "", "type": "string"}],
        "stateMutability": "view",
        "type": "function",
    },
]

for contract in contracts:
    c = w3.eth.contract(address=contract, abi=abi)

    decimals = c.functions.decimals().call()
    print(decimals)

    symbol = c.functions.symbol().call()
    print(symbol)

    totalSupply = c.functions.totalSupply().call()
    print(totalSupply)

    name = c.functions.name().call()
    print(name)

18
JEWEL
332768060356834244740242529
Jewels

18
OpenX
18834388163455816097261591
OpenSwap Token