1

I am trying to make a function more efficent, but getting the following error:

TypeError: Type uint256[4] memory is not implicitly convertible to expected type uint256[] memory.

Here is my funciton:

function requestUnstake(uint _stakeIndexNo) public returns(bool, uint) {
    AllUserStakedTimestamp storage allUserStakedTimestamp = allUserStakes[msg.sender];
    uint[] memory prm = [
        allUserStakedTimestamp._epochDuration[_stakeIndexNo], // interval
        allUserStakedTimestamp._timeOfStake[_stakeIndexNo],   // time at stake
        allUserStakedTimestamp._timesOfRelease[_stakeIndexNo],// time release
        allUserStakedTimestamp._rewardPerCycle[_stakeIndexNo] // reward per cycle
    ];

Any solution?

1 Answer 1

1

The error is telling you "I cannot implicitly create this array for you".

The hint is that you need to declare it explicitly, like so (putting the length 4 in the initialization):

Basic Example for Syntax

uint[4] memory balance = [uint(1), 2, 3, 4];

Your Case

So you need this:

uint[4] memory prm = [
        allUserStakedTimestamp._epochDuration[_stakeIndexNo], // interval
        allUserStakedTimestamp._timeOfStake[_stakeIndexNo],   // time at stake
        allUserStakedTimestamp._timesOfRelease[_stakeIndexNo],// time release
        allUserStakedTimestamp._rewardPerCycle[_stakeIndexNo] // reward per cycle
    ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.