I will try to test this endpoint https://docs.moralis.io/web3-data-api/evm/how-to-run-contract-functions
My contract data to test is 0x1A92f7381B9F03921564a437210bB9396471050C like this page
The function is getPrice
This function has not input parameters
abi = [
{
"inputs":[],
"name":"getPrice",
"outputs":[
{
"internalType":"uint256",
"name":"",
"type":"uint256"
}
],
"stateMutability":"view",
"type":"function"
}
]
api_key = "XXXXXXXXXXXXXXXXXXXXXxxxx" # Moralis
params = {
"address": "0x1A92f7381B9F03921564a437210bB9396471050C",
"function_name": "getPrice",
"chain": "eth",
}
body = {}
body['abi'] = abi
body['params'] = {}
result = evm_api.utils.run_contract_function(
api_key=api_key,
params=params,
body=body,
)
print(result)
The error code is: openapi_evm_api.exceptions.ApiTypeError: Invalid type. Required value type is frozendict and passed type was tuple at [βargs[0]β][βabiβ]
Do you have any idea to run this function in this contract?
With this function get abi complete using api rest etherscan
def ObtenerABI(contrato, red='Principal'):
'''Dado un contrato y una red obtnedo un json con el ABI del contrato
'''
API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXx'
if red == 'Principal':
ABI_ENDPOINT = 'https://api.etherscan.io/api?module=contract&action=getabi&address='
else:
ABI_ENDPOINT = 'https://api-goerli.etherscan.io/api?module=contract&action=getabi&address='
response = requests.get('%s%s&apikey=%s'%(ABI_ENDPOINT, contrato, API_KEY))
if response.status_code == 200:
response_json = response.json()
if response_json['status'] == '1':
abi_json = response_json['result']
else:
abi_json = {}
else:
abi_json = {}
return abi_json