I'm trying to read some data from VIEW function on already deployed contract using my own smart contract. The function is standart "balanceOf(address)" of ERC20 token. I can read this data using etherscan web interface and no transaction required for this action, but I can't find the way to do the same using smart contract. I have this code (let's assume I have no source code of deployed smart contract, so I'm using abi.encode):
pragma solidity ^0.5.15;
contract Test {
address dc = 0xaD6D458402F60fD3Bd25163575031ACDce07538D; //ropsten network ERC20 token address
uint number;
event Log(uint256 number, bytes b);
function balanceOf(address _val) public {
bool status;
bytes memory b;
(status, b) = dc.staticcall(abi.encodePacked(bytes4(keccak256("balanceOf(address)")), _val));
emit Log(number, b);
}}
but each time in Event Logs I see the same four numbers: 0 64 32 0
I tried to use staticcall, delegatedcall and call with no success. Can anyone suggest how can I read data from VIEW function?
Thanks!