from web3 import Web3
import json

CONTRACT_ADDRESS = "0x000480a262Fb3E9f07D3E2Bf8216E33a6e648e22"

# Load the ABI file
with open("ABI.json") as f:
    abi = json.load(f)

# Connect to Ganache
web3 = Web3(Web3.HTTPProvider('http://127.0.0.1:7545'))
if web3.is_connected():
    print("Connected to Ganache")
else: 
    print("Connection error: Couldn't connect to Ganache")

# Configure a contract object with the actual address and the ABI
contract = web3.eth.contract(address=CONTRACT_ADDRESS, abi=abi)

# List all available functions
print("Available functions: ")
for function in contract.all_functions():
    print(" " + str(function))

print("\n\n")

# Try to call the function getName
print("Testing call to function 'getName'")
print("It returns: " + contract.functions.getName().call())
