Hi there,
I just started with Moralis and I’m following your video tutorial on youtube. I created a simple token in solidity and I’m trying to call its function from the browser console in js, but I get an error.
Here an image of the console:
I’m using ganache and metamask is connected to my website.
This is the function I want to call that are inside my smart contract:
function stake(uint256 _amount) public {
// Make sure staker actually is good for it
require(_amount < balanceOf(msg.sender), "Cannot stake more than you own");
_stake(_amount);
// Burn the amount of tokens on the sender
_burn(msg.sender, _amount);
}
function hasStake(address _staker) public view returns(StakingSummary memory){
// totalStakeAmount is used to count total staked amount of the address
uint256 totalStakeAmount;
// Keep a summary in memory since we need to calculate this
StakingSummary memory summary = StakingSummary(0, stakeholders[stakes[_staker]].address_stakes);
// Itterate all stakes and grab amount of stakes
for (uint256 s = 0; s < summary.stakes.length; s += 1){
uint256 availableReward = calculateStakeReward(summary.stakes[s]);
summary.stakes[s].claimable = availableReward;
totalStakeAmount = totalStakeAmount+summary.stakes[s].amount;
}
// Assign calculate amount to summary
summary.total_amount = totalStakeAmount;
return summary;
}
Also, I have another 2 questions:
- When should I use .call({from: }) rather then .send({from: })?
- How can I read the return value of my “hasStake()” function after I called it?
Thank you in advance for your help!