mkdir pet_shop
cd pet_shop
truffle init
创建文件pet_shop,安装,用vscode打开
下载vscode高亮插件后,因为我用的solidity0.5.1,报错
Source file requires different compiler version (current compiler is 0.7.0+commit.9e61f92b.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
所以需要升级到0.7.0,
pragma solidity >=0.4.22 <0.8.0;
contract Adoption {
address[16] public adopters;
function adopt(uint petId) public returns (uint) {
require(petId>=0 && petId <=15);
adopters[petId] = msg.sender;
return petId;
}
function getAdopters() public view returns (address[16]) {
return adopters;
}
}
code:address[16]
error:Data location must be "memory" or "calldata" for return parameter in function, but none was given.
翻译:函数中返回参数的数据位置必须是“memory”或“calldata”,但是没有给出。
新版本变化。需要
标明 solidity数据位置-memory,storage和calldata,及其赋值行为。
vscode需要,高亮插件需要调到0.4版最合适
官方插件,设置,之前已经遇到了这种情况,换了台电脑,所以,要定期整理自己的笔记。
https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity
远程下载
选择远程下载时,编译器将从solc-bin信息库下载。
您需要使用工作区用户设置(当前项目)或全局用户设置(所有项目)的所需版本,更改以下用户设置,例如'latest'
或'v0.4.3+commit.2353da71'
。
"solidity.compileUsingRemoteVersion" : "latest"
我用的是远程方式,各种方式优先顺序和注意,转