2

I've been coding in solidity and got this error "Member "betsOnBitcoinGoesUp" is not available in struct BetOnBitcoinNew.BettingObject memory outside of storage." What does this mean?

The function that produced error looks like this.

function getUserBetsfromBettingObject(uint index, address callerAddress) constant returns (uint) {
BettingObject memory currentBettingObject = arrayOfBettingObjects[index];
if (currentBettingObject.currentState == GameState.bitcoinUpWon) {
  return currentBettingObject.betsOnBitcoinGoesUp[callerAddress];
} else if (currentBettingObject.currentState == GameState.bitcoinDownWon) {
  return currentBettingObject.betsOnBitcoinGoesDown[callerAddress];
} else {
  return 0;
}

}

2

As MSwezey states. The issue is because currentBettingObject is declared as BettingObject memory, not BettingObject storage.

Memory in the EVM is an array. Storage is a key value map (aka mapping). A map can not be represented as an array as they are fundamentally different data structures. Therefore Solidity mapping's only exist in storage they cannot exist in memory.

When doing BettingObject memory currentBettingObject = arrayOfBettingObjects[index]; you copy a BettingObject from storage into memory but since the mapping in the BettingObject can't be represented in the memory structure available (an array), it isn't copied and you get the error when trying to access it. If you replace that line with BettingObject storage currentBettingObject = arrayOfBettingObjects[index]; it will work since you're accessing the BettingObject in storage directly without copying it.

  • Much better explanation that I was too lazy to type. Well said! – MSwezey Jan 16 '18 at 2:46
1

I imported into my VS Code and got the same error.

The problem lies with the memory keyword used. Switching it to storage fixes this problem and the compiler error goes away.

Why?

See Roland's answer: Working with structure arrays in solidity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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