I'm trying to query the MAKER ERC20 contract and get the name and symbol of the token. The problem is that they are stored as a Bytes and I don't want to change the return type of my function from a String (since most other ERC20's names and symbols are stored as Strings).
So I'd need to add some code to handle the case in which it could be either string or bytes...
The problem is that I have no idea how to do this and I don't even fully understand what the .query() method is returning in the Web3 crate.
async fn get_token_info(
web3s: &web3::Web3<WebSocket>,
address: Address,
) -> Result<(String, String), Box<dyn std::error::Error>> {
let contract =
Contract::from_json(web3s.eth(), address, include_bytes!("erc20_abi.json")).unwrap();
let symbol: String = contract
.query("symbol", (), None, Options::default(), None)
.await
.unwrap();
let name: String = contract
.query("name", (), None, Options::default(), None)
.await
.unwrap();
Ok((symbol, name))
}