Using python 3.11.4, web3 6.9.0
I am using a reduced ERC20 token abi to be able to get decimal & symbol information. Abi is:
ERC20_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
}
]
W/ this, code works as expected. However, if I wrap the ABI definition in triple quotes:
ERC20_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
}
]"""
Then I get the following error:
apply_formatters_to_dict
raise ValueError(new_error_message) from exc
ValueError: Could not format invalid value '[\n {\n\t\t"inputs": [],\n "name": "decimals",\n "outputs": [{"internalType": "uint8", "name": "", "type": "uint8"}],\n "stateMutability": "view",\n "type": "function",\n "constant": True\n },\n {\n "inputs": [],\n "name": "symbol",\n "outputs": [{"internalType": "string", "name": "", "type": "string"}],\n "stateMutability": "view",\n "type": "function",\n "constant": True\n }\n]' as field 'abi'
Does anyone know why this ABI cannot be in JSON format? Not vital that it must be but I am curious why web3 is having trouble decoding it...