• 카테고리

    질문 & 답변
  • 세부 분야

    블록체인

  • 해결 여부

    미해결

Remix IDE 문법..

23.10.30 15:26 작성 조회수 187

0

아래 처럼 문법이 많이 바껴서 실습이 힘든것 같습니다..

아래버전으로는 에러가 나는 상황입니다..

 

The error occurred because the keyword "constant" is no longer used in the latest version of Solidity. In versions prior to 0.6.0, "constant" was used to indicate that a function does not modify the state of the contract. However, in Solidity 0.6.0 and later versions, the "view" keyword replaces "constant" to indicate that a function does not modify the state.

To fix the error, simply replace the keyword "constant" with "view" in the function declaration. Here's the corrected code:

pragma solidity ^0.8.18;

contract SimpleStorage {
uint storedData;

function set(uint x) {
storedData = x;
}

function get() view returns (uint) {
return storedData;
}
}

답변 2

·

답변을 작성해보세요.

0

문법이 많이 바뀌긴했죠. 솔리디티 버전을 낮추어서 해 보셔요~~~

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2023.11.01

안녕하세요 이채현 님, 인프런 AI 인턴이에요.
최신 버전의 Solidity에서는 “constant” 키워드 대신 “view” 키워드를 사용하게 되어 문법이 변경되었습니다. “constant” 키워드는 이전 버전의 Solidity에서 상태를 수정하지 않는 함수를 나타내는 데 사용되었습니다. 그러나 Solidity 0.6.0 이후의 버전에서는 “constant” 대신 “view” 키워드를 사용하여 함수가 상태를 수정하지 않음을 나타냅니다.

에러를 해결하기 위해서는 함수 선언에서 “constant” 키워드를 “view”로 대체하면 됩니다. 아래에 수정된 코드를 제공드리겠습니다:

pragma solidity ^0.8.18;

contract SimpleStorage {

uint storedData;

function set(uint x) {

    storedData = x;

}

function get() view returns (uint) {

    return storedData;

}

}

코드를 수정하시면 문제가 해결될 것입니다. 추가로 궁금한 점이 있으시면 언제든지 물어보세요! 감사합니다.