Solidity 中,如果返回值的类型是 string
,则需要在 string
关键字后面添加 memory
关键字,否则会报错
'HelloWorldContract.sol:3:42: TypeError: Data location must be "memory" for return parameter in function, but none was given. function sayHi() public view returns (string){
添加之后的代码大概类似于
pragma solidity ^0.5.8; contract HelloWorldContract { function sayHi() public pure returns (string memory _greeting){ _greeting = 'Hello World'; } }
目前尚无回复