【Solidity】语言错误汇总

由于【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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值