I want to get a token name from a smart contract address. I have come to a code using web3 module. It works nice, but I can not use web3 – the code will be used in the environment (BI service) that does not work with web3. So I need to change it to post request form. And I do not understand how to write parameters (payload in the code for request module). Could someone help?
The web3 code is:
from web3 import Web3
import json
web3 = Web3(Web3.HTTPProvider('https://rpc.ankr.com/eth'))
abi = [{"inputs": [], "name": "name", "outputs": [{"internalType": "string", "name": "", "type": "string"}],
"stateMutability": "view", "type": "function"},
{"inputs": [], "name": "symbol", "outputs": [{"internalType": "string", "name": "", "type": "string"}],
"stateMutability": "view", "type": "function"}]
address = Web3.to_checksum_address('0x3f1c1bfce3dc639a6bdf0e60210a94c1d97da231')
contract = web3.eth.contract(address, abi=abi)
token_name = contract.functions.name().call()
token_symbol = contract.functions.symbol().call()
print('Name:', token_name)
print('Symbol:', token_symbol)
And the request form:
import requests
url = 'https://rpc.ankr.com/eth'
address = '0x3f1c1bfce3dc639a6bdf0e60210a94c1d97da231'
payload = {}
response = requests.post(url, data=payload)
print(response.json())
I have checked docs for api but all the suggestions are for web3