I am facing an issue in solidity where When I declare the interface, it throws the error as shown in the title. at line 9
from solidity: ParserError: Function, variable, struct or modifier declaration expected. --> contracts/Program4.sol:9:3: | 9 | interface IL1ERC20Bridg
I checked the syntax and a few other errors of the same type on stack overflow, but to no avail.
https://ethereum.stackexchange.com/questions/90841/parsererror-function-variable-struct-or-modifier-declaration-expected I tried this one, but there is no incorrect white spaces.
https://ethereum.stackexchange.com/questions/120469/why-am-i-getting-function-variable-struct-or-modifier-declaration-expected The author had put a semicolan at the end thus prompting the error.
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);
}
You cannot declare an interface inside a contract. This type must be declared outside the smart contract and only in this way you can define an instance and call its methods or events . For this last operation you can use this statement:
[nameInterface] [nameVariable];
I adjusted your smart contract in this way:
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...
}