I am trying to read public variable from contract on chain using ethers.js.
Calling the methods work but I could not manage to read public property (without getter).
The methods works like this:
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed1.binance.org:443');
const contract = new ethers.Contract(address, [
'function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256)',
], provider);
let works = await contract.getMultiplier(5, 10);
However, if I try accessing public property, it doesn't work. In fact, I receive error with the ABI.
const contract = new ethers.Contract(address, [
'uint256 public totalAllocPoint',
'PoolInfo[] public poolInfo'
], provider);
Error: unsupported fragment (argument="value", value="uint256 public totalAllocPoint", code=INVALID_ARGUMENT, version=abi/5.2.0)
poolInfo
is even different because it needs a parameter.
How can I read totalAllocPoint
and poolInfo
from the contract?
Shouldn't it be like something like this:
let x = await contract.totalAllocPoint;
let y = await contract.poolInfo(2);
In the docs, unfortunately it only shows how to access methods