【Solidity】语言错误汇总【持续更新中。。。】
- 由于【Solidity】语言版本直接的差异性较大故,极易造成兼容性问题,故本文进行错误汇总
- TypeError: Data location must be "memory" or "calldata" for parameter in function, but none was given.
- TypeError: Invalid type for argument in function call. Invalid implicit conversion from string memory to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(...) to obtain the pre-0.5.0 behaviour or abi.encode(...) to use ABI encoding.
- TypeError: Contract "KittyInterface" should be marked as abstract
- TypeError: Functions without implementation must be marked virtual.
- TypeError: Contract "KittyInterface" should be marked as abstract
- TypeError: Data location must be "storage", "memory" or "calldata" for variable, but none was given.
- TypeError: "now" has been deprecated. Use "block.timestamp" instead.
- TypeError: Data location must be "storage", "memory" or "calldata" for parameter in function, but none was given.
由于【Solidity】语言版本直接的差异性较大故,极易造成兼容性问题,故本文进行错误汇总
你好! 这是作者第一次使用 Solidity语言 写智能合约,同时也是首次学习 Solidity语言 语法。又鉴于本次的版本是 >=0.8.2 <0.9.0,本文有不周之处谨请谅解,同时也欢迎大家批评指正。
TypeError: Data location must be “memory” or “calldata” for parameter in function, but none was given.
原因:报错处的函数中参数的数据位置必须是“memory”或“calldata”,但未给定任何位置。
解决:在报错处添加 “memory”或“calldata”。如下:
function feedandMultiply(uint _zombieId, uint _targetDna,string memory _species) public {]
TypeError: Invalid type for argument in function call. Invalid implicit conversion from string memory to bytes memory requested. This function requires a single bytes argument. Use abi.encodePacked(…) to obtain the pre-0.5.0 behaviour or abi.encode(…) to use ABI encoding.
解决:
if (keccak256("kitty") == keccak256(abi.encode(_species))) {
TypeError: Contract “KittyInterface” should be marked as abstract
解决:
abstract contract KittyInterface {
TypeError: Functions without implementation must be marked virtual.
解决:
abstract contract KittyInterface {
function getKitty(uint256 _id) virtual external view returns (
bool isGestating,
bool isReady,
uint256 cooldownIdenx,
uint256 nextActionAt,
uint256 siringWithId,
uint256 birthTime,
uint256 matronId,
uint256 sireId,
uint256 generation,
uint256 genes
);
}
TypeError: Contract “KittyInterface” should be marked as abstract
解决:
abstract contract KittyInterface {
TypeError: Data location must be “storage”, “memory” or “calldata” for variable, but none was given.
解决:
Zombie storage myZombie = zombies[_zombieId];
TypeError: “now” has been deprecated. Use “block.timestamp” instead.
解决:
now => block.timestamp
TypeError: Data location must be “storage”, “memory” or “calldata” for parameter in function, but none was given.
解决:
Zombie storage _zombie