Hi. I'm trying to get data from a public view with ethers.js using the pattern contractobject.callStatic.method(params) but It throwa an error: callStatic undefined.
Any way to fix this?
Sep 3, 2022, 12:24 AM
why callStatic if the function is a view function?
Sep 3, 2022, 8:03 AM
why you don't use just contract.method(param) ?
Sep 3, 2022, 10:21 AM
It asks for gas fees
Sep 3, 2022, 10:58 AM
then it is not a view function
Sep 3, 2022, 10:59 AM
as @FreezyDev told here, it's not a view or getter function.
Sep 3, 2022, 11:00 AM
please share screenshot
Sep 3, 2022, 11:01 AM
I can send the abi of the function
Sep 3, 2022, 11:05 AM
no
share the screenshot
of ethers;js
Sep 3, 2022, 11:05 AM
of what
Sep 3, 2022, 11:05 AM
of your script
Sep 3, 2022, 11:06 AM
here I'm trying without callStatic
Sep 3, 2022, 11:13 AM
please share with callStatic
Sep 3, 2022, 11:14 AM
Sep 3, 2022, 11:14 AM
the first call is a view right?
Sep 3, 2022, 11:15 AM
both are views
Sep 3, 2022, 11:16 AM
then you don't need callStatic
Sep 3, 2022, 11:16 AM
without It asks for fees tho
Sep 3, 2022, 11:16 AM
show contract code please
Sep 3, 2022, 11:16 AM
stakingBalance Is actually a public variable
Sep 3, 2022, 11:16 AM
please
share it
Sep 3, 2022, 11:17 AM
you dont need callStatic. just contract.stakingBalance (useraddress)
Sep 3, 2022, 11:17 AM
function calculateYieldTotal(address user) public view returns(uint256) {
uint256 time = calculateYieldTime(user) * 10**18;
uint256 timeRate = time / rate;
uint256 rawYield = (stakingBalance[user] * timeRate) / 10**18;
return rawYield;
}
uint256 time = calculateYieldTime(user) * 10**18;
uint256 timeRate = time / rate;
uint256 rawYield = (stakingBalance[user] * timeRate) / 10**18;
return rawYield;
}
Sep 3, 2022, 11:17 AM
ok and this ask for gas?
are you sure?
Sep 3, 2022, 11:18 AM
yes
Sep 3, 2022, 11:18 AM
strange
the other call?
Sep 3, 2022, 11:18 AM
both do
Sep 3, 2022, 11:18 AM
stakingBalance is a mapping
Sep 3, 2022, 11:18 AM
yes
Sep 3, 2022, 11:18 AM
try one sec to comment that line
leave only calculateYield call
also send here the contract link I try from my side
Sep 3, 2022, 11:19 AM
this is a view function. it can't ask for gas 😐
Sep 3, 2022, 11:19 AM
exactly
Sep 3, 2022, 11:20 AM
it asks for really low amount of gas but still does
Sep 3, 2022, 11:20 AM
please share link
Sep 3, 2022, 11:20 AM
https://mumbai.polygonscan.com/address/0x8229C6aa4D5E907a1bbeF0D168031Ec9767E8E65
Sep 3, 2022, 11:20 AM
ok wait
Sep 3, 2022, 11:21 AM
always try multiplication before division!
Sep 3, 2022, 11:21 AM
wdym
Sep 3, 2022, 11:21 AM
if you divide for a bigger number you get 0
1 / 2 = 0
btw he already does it
Sep 3, 2022, 11:23 AM
do you get gas fees too?
Sep 3, 2022, 11:28 AM
wait
ok so
how many calculations does it do?
how many calculations does it do?
Sep 3, 2022, 11:37 AM
function calculateYieldTime(address user) public view returns(uint256){
uint256 end = block.timestamp;
uint256 totalTime = end - startTime[user];
return totalTime;
}
function calculateYieldTotal(address user) public view returns(uint256) {
uint256 time = calculateYieldTime(user) * 10**18;
uint256 timeRate = time / rate;
uint256 rawYield = (stakingBalance[user] * timeRate) / 10**18;
return rawYield;
}
uint256 end = block.timestamp;
uint256 totalTime = end - startTime[user];
return totalTime;
}
function calculateYieldTotal(address user) public view returns(uint256) {
uint256 time = calculateYieldTime(user) * 10**18;
uint256 timeRate = time / rate;
uint256 rawYield = (stakingBalance[user] * timeRate) / 10**18;
return rawYield;
}
Sep 3, 2022, 11:44 AM
please share whole contract on pastebin and send link
will try to deploy on my end
will try to deploy on my end
if you want of course
or in the meanwhile share an address to check
Sep 3, 2022, 11:59 AM
contract Is deployed there, I'll send pastebin with Abi if you need
btw if I use those functions in remix they don't require gas fee
https://pastebin.com/84Yg6YSY
Sep 3, 2022, 12:13 PM
I can use on of the address that call Stake?
to check
ok
Sep 3, 2022, 12:25 PM
Connect with provider instead of signer
Hmm but I think it should've work anyway
Sep 3, 2022, 12:37 PM
tried
and it asked for a signer
and tried with a signer
and give estimated gas error
and give estimated gas error
Sep 3, 2022, 12:41 PM
Oh really? wierd stuff...
Maybe try verifying the contract. Probably would've changed code
Sep 3, 2022, 12:45 PM
I think so but if from remix work
ok it works
I tested with cast
cast call 0x8229C6aa4D5E907a1bbeF0D168031Ec9767E8E65 "calculateYieldTotal(address)(uint256)" 0x970e54dfaf8efe0a5f1398b5be6a9dbda1bfad9a --rpc-url https://rpc.ankr.com/polygon_mumbai
and it returns 55570788
Sep 3, 2022, 1:07 PM
and so why is it asking for gas from ether.js
Sep 3, 2022, 1:34 PM
i really don't know
Sep 3, 2022, 1:36 PM
I mean It Is also really low gas like .00006 Matic but It Is still asking also I saw on stackoverflow that someone was having the same issue but they solved with callStatic
Sep 3, 2022, 1:37 PM
https://twitter.com/wallet_guard/status/1565862728836718594
Sep 3, 2022, 1:54 PM
every week
Sep 3, 2022, 3:19 PM
btw I just realized I can't execute it without signer and don't know why
nvm just realized I'm dumb and I was using an old version of ether.js
Sep 3, 2022, 3:52 PM
well I was using the latest but same issuw
Sep 3, 2022, 4:16 PM
it is working for me now dk what just happened then
now I was trying to get approve on weth(mumbai testnet) but somehow 8000000000000000000 is an invalid number value
does solidity support numbers with scientific e notation?
Sep 3, 2022, 4:59 PM
no
Sep 3, 2022, 4:59 PM
That's what i thought so I used parseint After using toFixed(20) can the toFixed function be the problem?
Sep 3, 2022, 5:00 PM
10e9 yes
is an example
Sep 3, 2022, 5:02 PM
so I don't Need toFixed
Sep 3, 2022, 5:03 PM
if you input from ethers you can use string too
Sep 3, 2022, 5:06 PM
it is still saying invalid number both for strings, int and fixed int
Sep 3, 2022, 5:11 PM
show
Sep 3, 2022, 5:11 PM
value = dai.value * 10 ** 18
const tx = await DAIcontract.approve(NVAContractAddress, value)
dai is an input field
error: (arg="wad", reason="invalid number value", value=8000000000000000000, version=4.0.45)
const tx = await DAIcontract.approve(NVAContractAddress, value)
dai is an input field
error: (arg="wad", reason="invalid number value", value=8000000000000000000, version=4.0.45)
Sep 3, 2022, 5:12 PM
this is not string
(dai.value * 10**18).toString()
Sep 3, 2022, 5:16 PM
it works. Tysm
Sep 3, 2022, 5:18 PM