ParserError:需要函数、变量、结构或修饰符声明.溶解性^0.8



我面临着一个solidity问题,当我声明接口时,它会抛出标题中所示的错误。在9号线

from solidity:ParserError:需要函数、变量、结构或修饰符声明-->合同/程序4.sol:9:3:|9 |接口IL1ERC20Bridg

我检查了堆栈溢出时的语法和其他一些相同类型的错误,但没有用。

https://ethereum.stackexchange.com/questions/90841/parsererror-function-variable-struct-or-modifier-declaration-expected我试过这个,但没有不正确的空格。

https://ethereum.stackexchange.com/questions/120469/why-am-i-getting-function-variable-struct-or-modifier-declaration-expected作者在末尾加了一个分号,因此出现了错误。


pragma solidity ^0.8;
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import {Address} from '@openzeppelin/contracts/utils/Address.sol';
contract LendingPool 
{
interface IL1ERC20Bridge{
event ERC20DepositInitiated(
address indexed _l1Token, address indexed _l2Token,
address indexed _from, address _to, uint256 _amount, bytes _data);

event ERC20WithdrawalFinalized(
address indexed _l1Token, address indexed _l2Token,
address indexed _from, address _to, uint256 _amount, bytes _data);
}

不能在约定中声明接口。此类型必须在智能合约之外声明,只有这样才能定义实例并调用其方法或事件。对于最后一次操作,您可以使用以下语句:

[nameInterface] [nameVariable];

我以这种方式调整了你的智能合约:

pragma solidity ^0.8;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
interface IL1ERC20Bridge {
event ERC20DepositInitiated(
address indexed _l1Token, address indexed _l2Token,
address indexed _from, address _to, uint256 _amount, bytes _data);

event ERC20WithdrawalFinalized(
address indexed _l1Token, address indexed _l2Token,
address indexed _from, address _to, uint256 _amount, bytes _data);
}
contract LendingPool {
IL1ERC20Bridge myInterface;
// Your logic below this line...
}

我正在处理同样的问题。只是想用这个来结束合同。我添加了一个分号,但仍然有来自solidity:的解析错误

ParserError: Function, variable, struct or modifier declaration expected.
--> stable coin lil.sol:54:1:
|
54 | 
| ^

我该如何修复它?

function marketing(uint256 amount) public onlyOwner {
uint256 marketingTaxAmount = amount.mul(MARKETING_TAX).div(100);
_transfer(address(this), _msgSender(), marketingTaxAmount);
} 

最新更新