Read from chain
Solid allows you to read from the chain without any additional code.
Read an ERC20 balance
Let's read the balance of an ERC20 token.
ReadBalance.sol
pragma solidity ^0.8.0;
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
}
contract Main {
function main() public view returns {
// Replace with the address of the ERC20 token you want to read the balance of
uint256 balance = IERC20(0x1).balanceOf(0x2);
Console.logUint(balance);
}
}Now we can run the contract.
Terminal
solid run ReadBalance.solYou should see the following output:
Terminal
1000000