카테고리 없음
솔리디티 강좌 39강 - Interface 인터페이스
D_One
2021. 10. 8. 10:38
유튜브를 통해, 쉽고 간편하게 이해 해보아요!
https://youtu.be/7H9eb_6QRAk
- YouTube
www.youtube.com
구독/좋아요 해주셔서 감사합니다 :) !!
안녕하세요
오늘은 인터페이스에 대해서 알아보겠습니다.
Interface
interface : 스마트컨트랙 내에서 정의되어야할 필수 요소들 명시 합니다.
인터페이스 내에서는 세가지 규칙이 있습니다.
1, 함수는 external로 표시
2, enum, structs 가능
3, 변수, 생성자 불가(constructor X)
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 < 0.9.0;
interface ItemInfo {
struct item{
string name;
uint256 price;
}
function addItemInfo(string memory _name,uint256 _price) external;
function getItemInfo(uint256 _index) external view returns(item memory);
}
contract lec39 is ItemInfo{
item[] public itemList;
uint256[] public a;
function addItemInfo(string memory _name,uint256 _price) override public {
itemList.push(item(_name,_price));
}
function getItemInfo(uint256 _index) override public view returns(item memory) {
return itemList[_index];
}
}