Skip to content

함수 인자, 반환값에서 string(X) string memory(O) 이유!

MoSangIl edited this page Sep 10, 2021 · 4 revisions

string이란?

Types - Solidity 0.5.2 documentation - Array
Types - Solidity 0.5.2 documentation - Dynamically sized byte array

"Variables of type bytes and string are special arrays."

  • Solidity v5 공식문서에 의하면, string은 data Type이 아니라, special Array 중 하나라고 명시되어 있다.
  • 위 내용은 v5 버전에서 적용된 변화와 중요한 접점이 있다.

Solidity v0.5.0 Breaking Changes

Solidity v0.5.0 Breaking Changes - Solidity 0.5.0 documentation

"Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables."

  • 즉, struct, array, mapping type 의 모든 변수는 함수 인자와 반환값에 data Location(= memory OR storage)을 명시해야 한다!
  • string은 Array이므로, 함수 인자와 반환값에 memory 혹은 storage를 명시해야 하는 것이다.

구글링 - stackoverflow

TypeError: Data location must be "memory" for parameter in function, but none was given